home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / src / y.tab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-12  |  99.8 KB  |  3,597 lines

  1.  
  2. /*  A Bison parser, made from parse.y  */
  3.  
  4. #define    IF    258
  5. #define    THEN    259
  6. #define    ELSE    260
  7. #define    ELIF    261
  8. #define    FI    262
  9. #define    CASE    263
  10. #define    ESAC    264
  11. #define    FOR    265
  12. #define    WHILE    266
  13. #define    UNTIL    267
  14. #define    DO    268
  15. #define    DONE    269
  16. #define    FUNCTION    270
  17. #define    IN    271
  18. #define    BANG    272
  19. #define    WORD    273
  20. #define    NUMBER    274
  21. #define    AND_AND    275
  22. #define    OR_OR    276
  23. #define    GREATER_GREATER    277
  24. #define    LESS_LESS    278
  25. #define    LESS_AND    279
  26. #define    GREATER_AND    280
  27. #define    SEMI_SEMI    281
  28. #define    LESS_LESS_MINUS    282
  29. #define    AND_GREATER    283
  30. #define    LESS_GREATER    284
  31. #define    GREATER_BAR    285
  32. #define    yacc_EOF    286
  33.  
  34. #line 21 "parse.y"
  35.  
  36. #include <stdio.h>
  37. #include <signal.h>
  38. #include "shell.h"
  39. #include "flags.h"
  40.  
  41. #if defined (READLINE)
  42. #include <readline/readline.h>
  43. #endif /* READLINE */
  44.  
  45. #include <readline/history.h>
  46.  
  47. #define YYDEBUG 1
  48. extern int eof_encountered;
  49. extern int no_line_editing;
  50. extern int interactive, interactive_shell;
  51.  
  52. /* **************************************************************** */
  53. /*                                    */
  54. /*            "Forward" declarations                */
  55. /*                                    */
  56. /* **************************************************************** */
  57.  
  58.  
  59. /* This is kind of sickening.  In order to let these variables be seen by
  60.    all the functions that need them, I am forced to place their declarations
  61.    far away from the place where they should logically be found. */
  62.  
  63. /* prompt_string_pointer points to one of these, never to an actual string. */
  64. char *ps1_prompt, *ps2_prompt;
  65.  
  66. /* Handle on the current prompt string.     Indirectly points through
  67.    ps1_ or ps2_prompt. */
  68. char **prompt_string_pointer = (char **)NULL;
  69. char *current_prompt_string;
  70.  
  71. /* Variables to manage the task of reading here documents, because we need to
  72.    defer the reading until after a complete command has been collected. */
  73. REDIRECT *redirection_needing_here_doc = (REDIRECT *)NULL;
  74. int need_here_doc = 0;
  75.  
  76. #line 63 "parse.y"
  77. typedef union {
  78.   WORD_DESC *word;        /* the word that we read. */
  79.   int number;            /* the number that we read. */
  80.   WORD_LIST *word_list;
  81.   COMMAND *command;
  82.   REDIRECT *redirect;
  83.   ELEMENT element;
  84.   PATTERN_LIST *pattern;
  85. } YYSTYPE;
  86.  
  87. #ifndef YYLTYPE
  88. typedef
  89.   struct yyltype
  90.     {
  91.       int timestamp;
  92.       int first_line;
  93.       int first_column;
  94.       int last_line;
  95.       int last_column;
  96.       char *text;
  97.    }
  98.   yyltype;
  99.  
  100. #define YYLTYPE yyltype
  101. #endif
  102.  
  103. #include <stdio.h>
  104.  
  105. #ifndef __STDC__
  106. #define const
  107. #endif
  108.  
  109.  
  110.  
  111. #define    YYFINAL        212
  112. #define    YYFLAG        -32768
  113. #define    YYNTBASE    43
  114.  
  115. #define YYTRANSLATE(x) ((unsigned)(x) <= 286 ? yytranslate[x] : 66)
  116.  
  117. static const char yytranslate[] = {     0,
  118.      2,     2,     2,     2,     2,     2,     2,     2,     2,    33,
  119.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  120.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  121.      2,     2,     2,     2,     2,     2,     2,    31,     2,    41,
  122.     42,     2,     2,     2,    38,     2,     2,     2,     2,     2,
  123.      2,     2,     2,     2,     2,     2,     2,     2,    32,    37,
  124.      2,    36,     2,     2,     2,     2,     2,     2,     2,     2,
  125.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  126.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  127.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  128.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  129.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  130.      2,     2,    39,    35,    40,     2,     2,     2,     2,     2,
  131.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  132.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  133.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  134.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  135.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  136.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  137.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  138.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  139.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  140.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  141.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  142.      2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
  143.      2,     2,     2,     2,     2,     1,     2,     3,     4,     5,
  144.      6,     7,     8,     9,    10,    11,    12,    13,    14,    15,
  145.     16,    17,    18,    19,    20,    21,    22,    23,    24,    25,
  146.     26,    27,    28,    29,    30,    34
  147. };
  148.  
  149. static const short yyprhs[] = {     0,
  150.      0,     3,     5,     8,    10,    11,    14,    17,    20,    24,
  151.     28,    31,    35,    38,    42,    45,    49,    52,    56,    59,
  152.     63,    66,    70,    73,    77,    80,    83,    87,    90,    93,
  153.     97,    99,   101,   103,   106,   108,   111,   113,   115,   118,
  154.    125,   132,   140,   148,   159,   170,   177,   185,   192,   198,
  155.    206,   213,   219,   225,   229,   231,   237,   244,   249,   253,
  156.    258,   265,   271,   273,   276,   281,   286,   288,   291,   297,
  157.    303,   305,   309,   312,   314,   318,   322,   326,   331,   336,
  158.    341,   346,   351,   353,   356,   358,   360,   362,   363,   366,
  159.    368,   371,   374,   379,   384,   388,   392,   394,   397,   402
  160. };
  161.  
  162. static const short yyrhs[] = {    63,
  163.     33,     0,    33,     0,     1,    33,     0,    34,     0,     0,
  164.     44,    18,     0,    36,    18,     0,    37,    18,     0,    19,
  165.     36,    18,     0,    19,    37,    18,     0,    22,    18,     0,
  166.     19,    22,    18,     0,    23,    18,     0,    19,    23,    18,
  167.      0,    24,    19,     0,    19,    24,    19,     0,    25,    19,
  168.      0,    19,    25,    19,     0,    27,    18,     0,    19,    27,
  169.     18,     0,    25,    38,     0,    19,    25,    38,     0,    24,
  170.     38,     0,    19,    24,    38,     0,    28,    18,     0,    25,
  171.     18,     0,    19,    29,    18,     0,    29,    18,     0,    30,
  172.     18,     0,    19,    30,    18,     0,    18,     0,    45,     0,
  173.     45,     0,    47,    45,     0,    46,     0,    48,    46,     0,
  174.     48,     0,    50,     0,    50,    47,     0,    10,    18,    62,
  175.     13,    58,    14,     0,    10,    18,    62,    39,    58,    40,
  176.      0,    10,    18,    32,    62,    13,    58,    14,     0,    10,
  177.     18,    32,    62,    39,    58,    40,     0,    10,    18,    62,
  178.     16,    44,    61,    62,    13,    58,    14,     0,    10,    18,
  179.     62,    16,    44,    61,    62,    39,    58,    40,     0,     8,
  180.     18,    62,    16,    62,     9,     0,     8,    18,    62,    16,
  181.     55,    62,     9,     0,     8,    18,    62,    16,    53,     9,
  182.      0,     3,    58,     4,    58,     7,     0,     3,    58,     4,
  183.     58,     5,    58,     7,     0,     3,    58,     4,    58,    52,
  184.      7,     0,    11,    58,    13,    58,    14,     0,    12,    58,
  185.     13,    58,    14,     0,    41,    58,    42,     0,    51,     0,
  186.     18,    41,    42,    62,    51,     0,    15,    18,    41,    42,
  187.     62,    51,     0,    15,    18,    62,    51,     0,    39,    58,
  188.     40,     0,     6,    58,     4,    58,     0,     6,    58,     4,
  189.     58,     5,    58,     0,     6,    58,     4,    58,    52,     0,
  190.     54,     0,    55,    54,     0,    62,    57,    42,    58,     0,
  191.     62,    57,    42,    62,     0,    56,     0,    55,    56,     0,
  192.     62,    57,    42,    58,    26,     0,    62,    57,    42,    62,
  193.     26,     0,    18,     0,    57,    35,    18,     0,    62,    59,
  194.      0,    60,     0,    60,    33,    62,     0,    60,    31,    62,
  195.      0,    60,    32,    62,     0,    60,    20,    62,    60,     0,
  196.     60,    21,    62,    60,     0,    60,    31,    62,    60,     0,
  197.     60,    32,    62,    60,     0,    60,    33,    62,    60,     0,
  198.     65,     0,    17,    65,     0,    33,     0,    32,     0,    34,
  199.      0,     0,    62,    33,     0,    64,     0,    64,    31,     0,
  200.     64,    32,     0,    64,    20,    62,    64,     0,    64,    21,
  201.     62,    64,     0,    64,    31,    64,     0,    64,    32,    64,
  202.      0,    65,     0,    17,    65,     0,    65,    35,    62,    65,
  203.      0,    49,     0
  204. };
  205.  
  206. #if YYDEBUG != 0
  207. static const short yyrline[] = { 0,
  208.    102,   111,   118,   134,   144,   146,   150,   152,   154,   156,
  209.    158,   160,   162,   168,   174,   176,   178,   180,   182,   188,
  210.    194,   196,   198,   200,   202,   204,   206,   208,   218,   220,
  211.    224,   226,   230,   234,   245,   247,   251,   254,   257,   264,
  212.    266,   268,   270,   273,   275,   278,   280,   282,   287,   289,
  213.    291,   294,   296,   299,   302,   305,   308,   311,   315,   319,
  214.    321,   323,   328,   329,   333,   335,   339,   341,   345,   347,
  215.    351,   353,   362,   371,   372,   373,   375,   379,   381,   383,
  216.    385,   387,   389,   391,   398,   399,   400,   403,   404,   413,
  217.    420,   427,   436,   438,   440,   442,   444,   446,   453,   456
  218. };
  219.  
  220. static const char * const yytname[] = {   "$",
  221. "error","$illegal.","IF","THEN","ELSE","ELIF","FI","CASE","ESAC","FOR",
  222. "WHILE","UNTIL","DO","DONE","FUNCTION","IN","BANG","WORD","NUMBER","AND_AND",
  223. "OR_OR","GREATER_GREATER","LESS_LESS","LESS_AND","GREATER_AND","SEMI_SEMI","LESS_LESS_MINUS","AND_GREATER","LESS_GREATER","GREATER_BAR",
  224. "'&'","';'","'\\n'","yacc_EOF","'|'","'>'","'<'","'-'","'{'","'}'",
  225. "'('","')'","inputunit","words","redirection","simple_command_element","redirections","simple_command","command","shell_command",
  226. "group_command","elif_clause","case_clause_1","pattern_list_1","case_clause_sequence","pattern_list","pattern","list","list0","list1",
  227. "list_terminator","newlines","simple_list","simple_list1","pipeline",""
  228. };
  229. #endif
  230.  
  231. static const short yyr1[] = {     0,
  232.     43,    43,    43,    43,    44,    44,    45,    45,    45,    45,
  233.     45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
  234.     45,    45,    45,    45,    45,    45,    45,    45,    45,    45,
  235.     46,    46,    47,    47,    48,    48,    49,    49,    49,    50,
  236.     50,    50,    50,    50,    50,    50,    50,    50,    50,    50,
  237.     50,    50,    50,    50,    50,    50,    50,    50,    51,    52,
  238.     52,    52,    53,    53,    54,    54,    55,    55,    56,    56,
  239.     57,    57,    58,    59,    59,    59,    59,    60,    60,    60,
  240.     60,    60,    60,    60,    61,    61,    61,    62,    62,    63,
  241.     63,    63,    64,    64,    64,    64,    64,    64,    65,    65
  242. };
  243.  
  244. static const short yyr2[] = {     0,
  245.      2,     1,     2,     1,     0,     2,     2,     2,     3,     3,
  246.      2,     3,     2,     3,     2,     3,     2,     3,     2,     3,
  247.      2,     3,     2,     3,     2,     2,     3,     2,     2,     3,
  248.      1,     1,     1,     2,     1,     2,     1,     1,     2,     6,
  249.      6,     7,     7,    10,    10,     6,     7,     6,     5,     7,
  250.      6,     5,     5,     3,     1,     5,     6,     4,     3,     4,
  251.      6,     5,     1,     2,     4,     4,     1,     2,     5,     5,
  252.      1,     3,     2,     1,     3,     3,     3,     4,     4,     4,
  253.      4,     4,     1,     2,     1,     1,     1,     0,     2,     1,
  254.      2,     2,     4,     4,     3,     3,     1,     2,     4,     1
  255. };
  256.  
  257. static const short yydefact[] = {     0,
  258.      0,    88,     0,     0,    88,    88,     0,     0,    31,     0,
  259.      0,     0,     0,     0,     0,     0,     0,     0,     2,     4,
  260.      0,     0,    88,    88,    32,    35,    37,   100,    38,    55,
  261.      0,    90,    97,     3,     0,     0,    88,    88,     0,     0,
  262.     88,    98,     0,     0,     0,     0,     0,     0,     0,     0,
  263.      0,     0,    11,    13,    15,    23,    26,    17,    21,    19,
  264.     25,    28,    29,     7,     8,     0,     0,    31,    36,    33,
  265.     39,     1,    88,    88,    91,    92,    88,    88,     0,    89,
  266.     73,    74,    83,     0,    88,     0,    88,    88,     0,     0,
  267.     88,    12,    14,    16,    24,    18,    22,    20,    27,    30,
  268.      9,    10,    59,    54,    34,     0,     0,    95,    96,     0,
  269.      0,    84,    88,    88,    88,    88,    88,    88,     0,    88,
  270.      5,    88,     0,     0,    88,    58,     0,    93,    94,     0,
  271.      0,    99,    88,    88,    49,     0,     0,     0,    76,    77,
  272.     75,     0,    63,    88,    67,     0,    88,    88,     0,     0,
  273.      0,    52,    53,     0,    56,     0,     0,    51,    78,    79,
  274.     80,    81,    82,    48,    64,    68,     0,    46,    71,     0,
  275.      0,     0,    40,     6,    86,    85,    87,    88,    41,    57,
  276.     50,    88,    88,    88,    88,    47,     0,    88,    42,    43,
  277.      0,    60,     0,     0,     0,    72,    65,    66,    88,    88,
  278.     88,    62,    69,    70,     0,     0,    61,    44,    45,     0,
  279.      0,     0
  280. };
  281.  
  282. static const short yydefgoto[] = {   210,
  283.    150,    25,    26,    71,    27,    28,    29,    30,   136,   142,
  284.    143,   144,   145,   170,    35,    81,    82,   178,    36,    31,
  285.    108,    83
  286. };
  287.  
  288. static const short yypact[] = {   151,
  289.     -8,-32768,     9,    18,-32768,-32768,    24,   350,     7,   390,
  290.     41,    46,    20,    33,    48,    54,    66,    80,-32768,-32768,
  291.     85,    92,-32768,-32768,-32768,-32768,   374,-32768,    77,-32768,
  292.     21,   104,    76,-32768,   108,   222,-32768,    86,   114,   121,
  293.     96,    76,    79,   120,   122,    36,    37,   123,   126,   127,
  294.    130,   131,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  295. -32768,-32768,-32768,-32768,-32768,   111,    97,-32768,-32768,-32768,
  296.     77,-32768,-32768,-32768,   286,   286,-32768,-32768,   350,-32768,
  297. -32768,    99,    76,    -2,-32768,    -1,-32768,-32768,   116,   -11,
  298. -32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  299. -32768,-32768,-32768,-32768,-32768,   254,   254,    13,    13,   318,
  300.     63,    76,-32768,-32768,-32768,-32768,-32768,-32768,     4,-32768,
  301. -32768,-32768,   139,   150,-32768,-32768,   -11,-32768,-32768,   286,
  302.    286,-32768,-32768,-32768,-32768,   158,   222,   222,   222,   222,
  303.    222,   162,-32768,-32768,-32768,    11,-32768,-32768,   153,    47,
  304.    132,-32768,-32768,   -11,-32768,   175,   182,-32768,-32768,-32768,
  305.     56,    56,    56,-32768,-32768,-32768,    17,-32768,-32768,   -12,
  306.    177,   149,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
  307. -32768,-32768,-32768,-32768,-32768,-32768,   179,-32768,-32768,-32768,
  308.      8,    88,   222,   222,   222,-32768,   173,   190,-32768,-32768,
  309. -32768,-32768,-32768,-32768,   189,   164,-32768,-32768,-32768,   206,
  310.    210,-32768
  311. };
  312.  
  313. static const short yypgoto[] = {-32768,
  314. -32768,   -18,   184,-32768,-32768,-32768,-32768,   -87,    29,-32768,
  315.     78,-32768,    84,-32768,    -5,-32768,  -133,-32768,   -28,-32768,
  316.      2,    16
  317. };
  318.  
  319.  
  320. #define    YYLAST        427
  321.  
  322.  
  323. static const short yytable[] = {    39,
  324.     40,    32,   126,   159,   160,   161,   162,   163,    84,    86,
  325.     70,   120,    90,   118,   121,    33,   147,    66,    67,   168,
  326.    199,    80,   187,    42,    34,   186,    37,    23,   169,   188,
  327.     80,    80,    73,    74,   169,    38,    80,   122,    55,   155,
  328.     80,    41,   148,    80,   106,   107,   200,    43,   110,    80,
  329.     57,    58,   105,    72,    94,    96,   119,    56,    53,   161,
  330.    162,   163,   127,    54,   174,    60,   180,   133,   134,   135,
  331.     59,    61,   111,    95,    97,   113,   114,   109,   175,   176,
  332.    177,   123,   124,    62,   137,   138,   139,   140,   141,   146,
  333.     33,    33,   201,   134,   112,    10,   154,    63,    11,    12,
  334.     13,    14,    64,    15,    16,    17,    18,   128,   129,    65,
  335.     77,    78,    21,    22,   149,   167,   151,    85,   113,   114,
  336.     91,    33,    33,    73,    74,   132,    87,   156,   157,   115,
  337.    116,   117,   109,    88,    75,    76,    89,    92,   104,    93,
  338.     98,   171,   172,    99,   100,    33,    33,   101,   102,   191,
  339.    103,     1,   152,     2,   193,   194,   195,   125,     3,   198,
  340.      4,     5,     6,   153,   158,     7,   173,     8,     9,    10,
  341.    164,   179,    11,    12,    13,    14,   192,    15,    16,    17,
  342.     18,   181,   197,    19,    20,   182,    21,    22,   190,    23,
  343.    189,    24,     2,   205,   206,   207,   196,     3,   203,     4,
  344.      5,     6,   208,   209,     7,   211,    79,     9,    10,   212,
  345.     69,    11,    12,    13,    14,   204,    15,    16,    17,    18,
  346.    202,   165,    80,     0,     2,    21,    22,   166,    23,     3,
  347.     24,     4,     5,     6,     0,     0,     7,     0,    79,     9,
  348.     10,     0,     0,    11,    12,    13,    14,     0,    15,    16,
  349.     17,    18,     0,     0,    80,     0,     2,    21,    22,     0,
  350.     23,     3,    24,     4,     5,     6,     0,     0,     7,     0,
  351.      8,     9,    10,     0,     0,    11,    12,    13,    14,     0,
  352.     15,    16,    17,    18,     0,     0,    80,     0,     2,    21,
  353.     22,     0,    23,     3,    24,     4,     5,     6,     0,     0,
  354.      7,     0,     8,     9,    10,     0,     0,    11,    12,    13,
  355.     14,     0,    15,    16,    17,    18,     0,     0,     0,     0,
  356.      2,    21,    22,     0,    23,     3,    24,     4,     5,     6,
  357.      0,     0,     7,     0,     0,     9,    10,     0,     0,    11,
  358.     12,    13,    14,     0,    15,    16,    17,    18,     0,     0,
  359.     80,     0,     2,    21,    22,     0,    23,     3,    24,     4,
  360.      5,     6,     0,     0,     7,     0,     0,     9,    10,     0,
  361.      0,    11,    12,    13,    14,     0,    15,    16,    17,    18,
  362.      0,     0,     0,     0,     0,    21,    22,     0,    23,     0,
  363.     24,    68,    10,     0,     0,    11,    12,    13,    14,     0,
  364.     15,    16,    17,    18,     0,     0,     0,     0,     0,    21,
  365.     22,    44,    45,    46,    47,     0,    48,     0,    49,    50,
  366.      0,     0,     0,     0,     0,    51,    52
  367. };
  368.  
  369. static const short yycheck[] = {     5,
  370.      6,     0,    90,   137,   138,   139,   140,   141,    37,    38,
  371.     29,    13,    41,    16,    16,     0,    13,    23,    24,     9,
  372.     13,    33,    35,     8,    33,     9,    18,    39,    18,    42,
  373.     33,    33,    20,    21,    18,    18,    33,    39,    19,   127,
  374.     33,    18,    39,    33,    73,    74,    39,    41,    77,    33,
  375.     18,    19,    71,    33,    19,    19,    85,    38,    18,   193,
  376.    194,   195,    91,    18,    18,    18,   154,     5,     6,     7,
  377.     38,    18,    78,    38,    38,    20,    21,    76,    32,    33,
  378.     34,    87,    88,    18,   113,   114,   115,   116,   117,   118,
  379.     75,    76,     5,     6,    79,    19,   125,    18,    22,    23,
  380.     24,    25,    18,    27,    28,    29,    30,   106,   107,    18,
  381.     35,     4,    36,    37,   120,   144,   122,    32,    20,    21,
  382.     42,   106,   107,    20,    21,   110,    13,   133,   134,    31,
  383.     32,    33,   131,    13,    31,    32,    41,    18,    42,    18,
  384.     18,   147,   148,    18,    18,   130,   131,    18,    18,   178,
  385.     40,     1,    14,     3,   183,   184,   185,    42,     8,   188,
  386.     10,    11,    12,    14,     7,    15,    14,    17,    18,    19,
  387.      9,    40,    22,    23,    24,    25,   182,    27,    28,    29,
  388.     30,     7,   188,    33,    34,     4,    36,    37,    40,    39,
  389.     14,    41,     3,   199,   200,   201,    18,     8,    26,    10,
  390.     11,    12,    14,    40,    15,     0,    17,    18,    19,     0,
  391.     27,    22,    23,    24,    25,    26,    27,    28,    29,    30,
  392.    192,   144,    33,    -1,     3,    36,    37,   144,    39,     8,
  393.     41,    10,    11,    12,    -1,    -1,    15,    -1,    17,    18,
  394.     19,    -1,    -1,    22,    23,    24,    25,    -1,    27,    28,
  395.     29,    30,    -1,    -1,    33,    -1,     3,    36,    37,    -1,
  396.     39,     8,    41,    10,    11,    12,    -1,    -1,    15,    -1,
  397.     17,    18,    19,    -1,    -1,    22,    23,    24,    25,    -1,
  398.     27,    28,    29,    30,    -1,    -1,    33,    -1,     3,    36,
  399.     37,    -1,    39,     8,    41,    10,    11,    12,    -1,    -1,
  400.     15,    -1,    17,    18,    19,    -1,    -1,    22,    23,    24,
  401.     25,    -1,    27,    28,    29,    30,    -1,    -1,    -1,    -1,
  402.      3,    36,    37,    -1,    39,     8,    41,    10,    11,    12,
  403.     -1,    -1,    15,    -1,    -1,    18,    19,    -1,    -1,    22,
  404.     23,    24,    25,    -1,    27,    28,    29,    30,    -1,    -1,
  405.     33,    -1,     3,    36,    37,    -1,    39,     8,    41,    10,
  406.     11,    12,    -1,    -1,    15,    -1,    -1,    18,    19,    -1,
  407.     -1,    22,    23,    24,    25,    -1,    27,    28,    29,    30,
  408.     -1,    -1,    -1,    -1,    -1,    36,    37,    -1,    39,    -1,
  409.     41,    18,    19,    -1,    -1,    22,    23,    24,    25,    -1,
  410.     27,    28,    29,    30,    -1,    -1,    -1,    -1,    -1,    36,
  411.     37,    22,    23,    24,    25,    -1,    27,    -1,    29,    30,
  412.     -1,    -1,    -1,    -1,    -1,    36,    37
  413. };
  414. /* -*-C-*-  Note some compilers choke on comments on `#line' lines.  */
  415. #line 3 "/net/acae127/home/bammi/lib/bison.simple"
  416.  
  417. /* Skeleton output parser for bison,
  418.    Copyright (C) 1984, 1989, 1990 Bob Corbett and Richard Stallman
  419.  
  420.    This program is free software; you can redistribute it and/or modify
  421.    it under the terms of the GNU General Public License as published by
  422.    the Free Software Foundation; either version 1, or (at your option)
  423.    any later version.
  424.  
  425.    This program is distributed in the hope that it will be useful,
  426.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  427.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  428.    GNU General Public License for more details.
  429.  
  430.    You should have received a copy of the GNU General Public License
  431.    along with this program; if not, write to the Free Software
  432.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  433.  
  434.  
  435. #ifndef alloca
  436. #ifdef __GNUC__
  437. #define alloca __builtin_alloca
  438. #else /* Not GNU C.  */
  439. #if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
  440. #include <alloca.h>
  441. #else /* Not sparc */
  442. #ifdef MSDOS
  443. #include <malloc.h>
  444. #endif /* MSDOS */
  445. #endif /* Not sparc.  */
  446. #endif /* Not GNU C.  */
  447. #endif /* alloca not defined.  */
  448.  
  449. /* This is the parser code that is written into each bison parser
  450.   when the %semantic_parser declaration is not specified in the grammar.
  451.   It was written by Richard Stallman by simplifying the hairy parser
  452.   used when %semantic_parser is specified.  */
  453.  
  454. /* Note: there must be only one dollar sign in this file.
  455.    It is replaced by the list of actions, each action
  456.    as one case of the switch.  */
  457.  
  458. #define yyerrok        (yyerrstatus = 0)
  459. #define yyclearin    (yychar = YYEMPTY)
  460. #define YYEMPTY        -2
  461. #define YYEOF        0
  462. #define YYACCEPT    return(0)
  463. #define YYABORT     return(1)
  464. #define YYERROR        goto yyerrlab1
  465. /* Like YYERROR except do call yyerror.
  466.    This remains here temporarily to ease the
  467.    transition to the new meaning of YYERROR, for GCC.
  468.    Once GCC version 2 has supplanted version 1, this can go.  */
  469. #define YYFAIL        goto yyerrlab
  470. #define YYRECOVERING()  (!!yyerrstatus)
  471. #define YYBACKUP(token, value) \
  472. do                                \
  473.   if (yychar == YYEMPTY && yylen == 1)                \
  474.     { yychar = (token), yylval = (value);            \
  475.       yychar1 = YYTRANSLATE (yychar);                \
  476.       YYPOPSTACK;                        \
  477.       goto yybackup;                        \
  478.     }                                \
  479.   else                                \
  480.     { yyerror ("syntax error: cannot back up"); YYERROR; }    \
  481. while (0)
  482.  
  483. #define YYTERROR    1
  484. #define YYERRCODE    256
  485.  
  486. #ifndef YYPURE
  487. #define YYLEX        yylex()
  488. #endif
  489.  
  490. #ifdef YYPURE
  491. #ifdef YYLSP_NEEDED
  492. #define YYLEX        yylex(&yylval, &yylloc)
  493. #else
  494. #define YYLEX        yylex(&yylval)
  495. #endif
  496. #endif
  497.  
  498. /* If nonreentrant, generate the variables here */
  499.  
  500. #ifndef YYPURE
  501.  
  502. int    yychar;            /*  the lookahead symbol        */
  503. YYSTYPE    yylval;            /*  the semantic value of the        */
  504.                 /*  lookahead symbol            */
  505.  
  506. #ifdef YYLSP_NEEDED
  507. YYLTYPE yylloc;            /*  location data for the lookahead    */
  508.                 /*  symbol                */
  509. #endif
  510.  
  511. int yynerrs;            /*  number of parse errors so far       */
  512. #endif  /* not YYPURE */
  513.  
  514. #if YYDEBUG != 0
  515. int yydebug;            /*  nonzero means print parse trace    */
  516. /* Since this is uninitialized, it does not stop multiple parsers
  517.    from coexisting.  */
  518. #endif
  519.  
  520. /*  YYINITDEPTH indicates the initial size of the parser's stacks    */
  521.  
  522. #ifndef    YYINITDEPTH
  523. #define YYINITDEPTH 200
  524. #endif
  525.  
  526. /*  YYMAXDEPTH is the maximum size the stacks can grow to
  527.     (effective only if the built-in stack extension method is used).  */
  528.  
  529. #if YYMAXDEPTH == 0
  530. #undef YYMAXDEPTH
  531. #endif
  532.  
  533. #ifndef YYMAXDEPTH
  534. #define YYMAXDEPTH 10000
  535. #endif
  536.  
  537. #ifndef __cplusplus
  538.  
  539. /* This is the most reliable way to avoid incompatibilities
  540.    in available built-in functions on various systems.  */
  541. static void
  542. __yy_bcopy (from, to, count)
  543.      char *from;
  544.      char *to;
  545.      int count;
  546. {
  547.   register char *f = from;
  548.   register char *t = to;
  549.   register int i = count;
  550.  
  551.   while (i-- > 0)
  552.     *t++ = *f++;
  553. }
  554.  
  555. #else /* __cplusplus */
  556.  
  557. /* This is the most reliable way to avoid incompatibilities
  558.    in available built-in functions on various systems.  */
  559. static void
  560. __yy_bcopy (char *from, char *to, int count)
  561. {
  562.   register char *f = from;
  563.   register char *t = to;
  564.   register int i = count;
  565.  
  566.   while (i-- > 0)
  567.     *t++ = *f++;
  568. }
  569.  
  570. #endif
  571.  
  572. #line 160 "/net/acae127/home/bammi/lib/bison.simple"
  573. int
  574. yyparse()
  575. {
  576.   register int yystate;
  577.   register int yyn;
  578.   register short *yyssp;
  579.   register YYSTYPE *yyvsp;
  580.   int yyerrstatus;    /*  number of tokens to shift before error messages enabled */
  581.   int yychar1;        /*  lookahead token as an internal (translated) token number */
  582.  
  583.   short    yyssa[YYINITDEPTH];    /*  the state stack            */
  584.   YYSTYPE yyvsa[YYINITDEPTH];    /*  the semantic value stack        */
  585.  
  586.   short *yyss = yyssa;        /*  refer to the stacks thru separate pointers */
  587.   YYSTYPE *yyvs = yyvsa;    /*  to allow yyoverflow to reallocate them elsewhere */
  588.  
  589. #ifdef YYLSP_NEEDED
  590.   YYLTYPE *yyls = yylsa;
  591.   YYLTYPE *yylsp;
  592.   YYLTYPE yylsa[YYINITDEPTH];    /*  the location stack            */
  593.  
  594. #define YYPOPSTACK   (yyvsp--, yysp--, yylsp--)
  595. #else
  596. #define YYPOPSTACK   (yyvsp--, yysp--)
  597. #endif
  598.  
  599.   int yystacksize = YYINITDEPTH;
  600.  
  601. #ifdef YYPURE
  602.   int yychar;
  603.   YYSTYPE yylval;
  604.   int yynerrs;
  605. #ifdef YYLSP_NEEDED
  606.   YYLTYPE yylloc;
  607. #endif
  608. #endif
  609.  
  610.   YYSTYPE yyval;        /*  the variable used to return        */
  611.                 /*  semantic values from the action    */
  612.                 /*  routines                */
  613.  
  614.   int yylen;
  615.  
  616. #if YYDEBUG != 0
  617.   if (yydebug)
  618.     fprintf(stderr, "Starting parse\n");
  619. #endif
  620.  
  621.   yystate = 0;
  622.   yyerrstatus = 0;
  623.   yynerrs = 0;
  624.   yychar = YYEMPTY;        /* Cause a token to be read.  */
  625.  
  626.   /* Initialize stack pointers.
  627.      Waste one element of value and location stack
  628.      so that they stay on the same level as the state stack.  */
  629.  
  630.   yyssp = yyss - 1;
  631.   yyvsp = yyvs;
  632. #ifdef YYLSP_NEEDED
  633.   yylsp = yyls;
  634. #endif
  635.  
  636. /* Push a new state, which is found in  yystate  .  */
  637. /* In all cases, when you get here, the value and location stacks
  638.    have just been pushed. so pushing a state here evens the stacks.  */
  639. yynewstate:
  640.  
  641.   *++yyssp = yystate;
  642.  
  643.   if (yyssp >= yyss + yystacksize - 1)
  644.     {
  645.       /* Give user a chance to reallocate the stack */
  646.       /* Use copies of these so that the &'s don't force the real ones into memory. */
  647.       YYSTYPE *yyvs1 = yyvs;
  648.       short *yyss1 = yyss;
  649. #ifdef YYLSP_NEEDED
  650.       YYLTYPE *yyls1 = yyls;
  651. #endif
  652.  
  653.       /* Get the current used size of the three stacks, in elements.  */
  654.       int size = yyssp - yyss + 1;
  655.  
  656. #ifdef yyoverflow
  657.       /* Each stack pointer address is followed by the size of
  658.      the data in use in that stack, in bytes.  */
  659.       yyoverflow("parser stack overflow",
  660.          &yyss1, size * sizeof (*yyssp),
  661.          &yyvs1, size * sizeof (*yyvsp),
  662. #ifdef YYLSP_NEEDED
  663.          &yyls1, size * sizeof (*yylsp),
  664. #endif
  665.          &yystacksize);
  666.  
  667.       yyss = yyss1; yyvs = yyvs1;
  668. #ifdef YYLSP_NEEDED
  669.       yyls = yyls1;
  670. #endif
  671. #else /* no yyoverflow */
  672.       /* Extend the stack our own way.  */
  673.       if (yystacksize >= YYMAXDEPTH)
  674.     {
  675.       yyerror("parser stack overflow");
  676.       return 2;
  677.     }
  678.       yystacksize *= 2;
  679.       if (yystacksize > YYMAXDEPTH)
  680.     yystacksize = YYMAXDEPTH;
  681.       yyss = (short *) alloca (yystacksize * sizeof (*yyssp));
  682.       __yy_bcopy ((char *)yyss1, (char *)yyss, size * sizeof (*yyssp));
  683.       yyvs = (YYSTYPE *) alloca (yystacksize * sizeof (*yyvsp));
  684.       __yy_bcopy ((char *)yyvs1, (char *)yyvs, size * sizeof (*yyvsp));
  685. #ifdef YYLSP_NEEDED
  686.       yyls = (YYLTYPE *) alloca (yystacksize * sizeof (*yylsp));
  687.       __yy_bcopy ((char *)yyls1, (char *)yyls, size * sizeof (*yylsp));
  688. #endif
  689. #endif /* no yyoverflow */
  690.  
  691.       yyssp = yyss + size - 1;
  692.       yyvsp = yyvs + size - 1;
  693. #ifdef YYLSP_NEEDED
  694.       yylsp = yyls + size - 1;
  695. #endif
  696.  
  697. #if YYDEBUG != 0
  698.       if (yydebug)
  699.     fprintf(stderr, "Stack size increased to %d\n", yystacksize);
  700. #endif
  701.  
  702.       if (yyssp >= yyss + yystacksize - 1)
  703.     YYABORT;
  704.     }
  705.  
  706. #if YYDEBUG != 0
  707.   if (yydebug)
  708.     fprintf(stderr, "Entering state %d\n", yystate);
  709. #endif
  710.  
  711.  yybackup:
  712.  
  713. /* Do appropriate processing given the current state.  */
  714. /* Read a lookahead token if we need one and don't already have one.  */
  715. /* yyresume: */
  716.  
  717.   /* First try to decide what to do without reference to lookahead token.  */
  718.  
  719.   yyn = yypact[yystate];
  720.   if (yyn == YYFLAG)
  721.     goto yydefault;
  722.  
  723.   /* Not known => get a lookahead token if don't already have one.  */
  724.  
  725.   /* yychar is either YYEMPTY or YYEOF
  726.      or a valid token in external form.  */
  727.  
  728.   if (yychar == YYEMPTY)
  729.     {
  730. #if YYDEBUG != 0
  731.       if (yydebug)
  732.     fprintf(stderr, "Reading a token: ");
  733. #endif
  734.       yychar = YYLEX;
  735.     }
  736.  
  737.   /* Convert token to internal form (in yychar1) for indexing tables with */
  738.  
  739.   if (yychar <= 0)        /* This means end of input. */
  740.     {
  741.       yychar1 = 0;
  742.       yychar = YYEOF;        /* Don't call YYLEX any more */
  743.  
  744. #if YYDEBUG != 0
  745.       if (yydebug)
  746.     fprintf(stderr, "Now at end of input.\n");
  747. #endif
  748.     }
  749.   else
  750.     {
  751.       yychar1 = YYTRANSLATE(yychar);
  752.  
  753. #if YYDEBUG != 0
  754.       if (yydebug)
  755.     fprintf(stderr, "Next token is %d (%s)\n", yychar, yytname[yychar1]);
  756. #endif
  757.     }
  758.  
  759.   yyn += yychar1;
  760.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
  761.     goto yydefault;
  762.  
  763.   yyn = yytable[yyn];
  764.  
  765.   /* yyn is what to do for this token type in this state.
  766.      Negative => reduce, -yyn is rule number.
  767.      Positive => shift, yyn is new state.
  768.        New state is final state => don't bother to shift,
  769.        just return success.
  770.      0, or most negative number => error.  */
  771.  
  772.   if (yyn < 0)
  773.     {
  774.       if (yyn == YYFLAG)
  775.     goto yyerrlab;
  776.       yyn = -yyn;
  777.       goto yyreduce;
  778.     }
  779.   else if (yyn == 0)
  780.     goto yyerrlab;
  781.  
  782.   if (yyn == YYFINAL)
  783.     YYACCEPT;
  784.  
  785.   /* Shift the lookahead token.  */
  786.  
  787. #if YYDEBUG != 0
  788.   if (yydebug)
  789.     fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
  790. #endif
  791.  
  792.   /* Discard the token being shifted unless it is eof.  */
  793.   if (yychar != YYEOF)
  794.     yychar = YYEMPTY;
  795.  
  796.   *++yyvsp = yylval;
  797. #ifdef YYLSP_NEEDED
  798.   *++yylsp = yylloc;
  799. #endif
  800.  
  801.   /* count tokens shifted since error; after three, turn off error status.  */
  802.   if (yyerrstatus) yyerrstatus--;
  803.  
  804.   yystate = yyn;
  805.   goto yynewstate;
  806.  
  807. /* Do the default action for the current state.  */
  808. yydefault:
  809.  
  810.   yyn = yydefact[yystate];
  811.   if (yyn == 0)
  812.     goto yyerrlab;
  813.  
  814. /* Do a reduction.  yyn is the number of a rule to reduce with.  */
  815. yyreduce:
  816.   yylen = yyr2[yyn];
  817.   yyval = yyvsp[1-yylen]; /* implement default value of the action */
  818.  
  819. #if YYDEBUG != 0
  820.   if (yydebug)
  821.     {
  822.       int i;
  823.  
  824.       fprintf (stderr, "Reducing via rule %d (line %d), ",
  825.            yyn, yyrline[yyn]);
  826.  
  827.       /* Print the symboles being reduced, and their result.  */
  828.       for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
  829.     fprintf (stderr, "%s ", yytname[yyrhs[i]]);
  830.       fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
  831.     }
  832. #endif
  833.  
  834.  
  835.   switch (yyn) {
  836.  
  837. case 1:
  838. #line 103 "parse.y"
  839. {
  840.               /* Case of regular command.  Discard the error
  841.                  safety net,and return the command just parsed. */
  842.               global_command = yyvsp[-1].command;
  843.               eof_encountered = 0;
  844.               discard_parser_constructs (0);
  845.               YYACCEPT;
  846.             ;
  847.     break;}
  848. case 2:
  849. #line 112 "parse.y"
  850. {
  851.               /* Case of regular command, but not a very
  852.                  interesting one.  Return a NULL command. */
  853.               global_command = (COMMAND *)NULL;
  854.               YYACCEPT;
  855.             ;
  856.     break;}
  857. case 3:
  858. #line 120 "parse.y"
  859. {
  860.               /* Error during parsing.  Return NULL command. */
  861.               global_command = (COMMAND *)NULL;
  862.               eof_encountered = 0;
  863.               discard_parser_constructs (1);
  864.               if (interactive)
  865.                 {
  866.                   YYACCEPT;
  867.                 }
  868.               else
  869.                 {
  870.                   YYABORT;
  871.                 }
  872.             ;
  873.     break;}
  874. case 4:
  875. #line 135 "parse.y"
  876. {
  877.               /* Case of EOF seen by itself.  Do ignoreeof or 
  878.                  not. */
  879.               global_command = (COMMAND *)NULL;
  880.               handle_eof_input_unit ();
  881.               YYACCEPT;
  882.             ;
  883.     break;}
  884. case 5:
  885. #line 145 "parse.y"
  886. { yyval.word_list = (WORD_LIST *)NULL; ;
  887.     break;}
  888. case 6:
  889. #line 147 "parse.y"
  890. { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-1].word_list); ;
  891.     break;}
  892. case 7:
  893. #line 151 "parse.y"
  894. { yyval.redirect = make_redirection ( 1, r_output_direction, yyvsp[0].word); ;
  895.     break;}
  896. case 8:
  897. #line 153 "parse.y"
  898. { yyval.redirect = make_redirection ( 0, r_input_direction, yyvsp[0].word); ;
  899.     break;}
  900. case 9:
  901. #line 155 "parse.y"
  902. { yyval.redirect = make_redirection (yyvsp[-2].number, r_output_direction, yyvsp[0].word); ;
  903.     break;}
  904. case 10:
  905. #line 157 "parse.y"
  906. { yyval.redirect = make_redirection (yyvsp[-2].number, r_input_direction, yyvsp[0].word); ;
  907.     break;}
  908. case 11:
  909. #line 159 "parse.y"
  910. { yyval.redirect = make_redirection ( 1, r_appending_to, yyvsp[0].word); ;
  911.     break;}
  912. case 12:
  913. #line 161 "parse.y"
  914. { yyval.redirect = make_redirection (yyvsp[-2].number, r_appending_to, yyvsp[0].word); ;
  915.     break;}
  916. case 13:
  917. #line 163 "parse.y"
  918. {
  919.               yyval.redirect = make_redirection ( 0, r_reading_until, yyvsp[0].word);
  920.               redirection_needing_here_doc = yyval.redirect;
  921.               need_here_doc = 1;
  922.             ;
  923.     break;}
  924. case 14:
  925. #line 169 "parse.y"
  926. {
  927.               yyval.redirect = make_redirection (yyvsp[-2].number, r_reading_until, yyvsp[0].word);
  928.               redirection_needing_here_doc = yyval.redirect;
  929.               need_here_doc = 1;
  930.             ;
  931.     break;}
  932. case 15:
  933. #line 175 "parse.y"
  934. { yyval.redirect = make_redirection ( 0, r_duplicating, yyvsp[0].number); ;
  935.     break;}
  936. case 16:
  937. #line 177 "parse.y"
  938. { yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating, yyvsp[0].number); ;
  939.     break;}
  940. case 17:
  941. #line 179 "parse.y"
  942. { yyval.redirect = make_redirection ( 1, r_duplicating, yyvsp[0].number); ;
  943.     break;}
  944. case 18:
  945. #line 181 "parse.y"
  946. { yyval.redirect = make_redirection (yyvsp[-2].number, r_duplicating, yyvsp[0].number); ;
  947.     break;}
  948. case 19:
  949. #line 183 "parse.y"
  950. {
  951.               yyval.redirect = make_redirection ( 0, r_deblank_reading_until, yyvsp[0].word);
  952.               redirection_needing_here_doc = yyval.redirect;
  953.               need_here_doc = 1;
  954.             ;
  955.     break;}
  956. case 20:
  957. #line 189 "parse.y"
  958. {
  959.               yyval.redirect = make_redirection (yyvsp[-2].number, r_deblank_reading_until, yyvsp[0].word);
  960.               redirection_needing_here_doc = yyval.redirect;
  961.               need_here_doc = 1;
  962.             ;
  963.     break;}
  964. case 21:
  965. #line 195 "parse.y"
  966. { yyval.redirect = make_redirection ( 1, r_close_this, 0); ;
  967.     break;}
  968. case 22:
  969. #line 197 "parse.y"
  970. { yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, 0); ;
  971.     break;}
  972. case 23:
  973. #line 199 "parse.y"
  974. { yyval.redirect = make_redirection ( 0, r_close_this, 0); ;
  975.     break;}
  976. case 24:
  977. #line 201 "parse.y"
  978. { yyval.redirect = make_redirection (yyvsp[-2].number, r_close_this, 0); ;
  979.     break;}
  980. case 25:
  981. #line 203 "parse.y"
  982. { yyval.redirect = make_redirection ( 1, r_err_and_out, yyvsp[0].word); ;
  983.     break;}
  984. case 26:
  985. #line 205 "parse.y"
  986. { yyval.redirect = make_redirection ( 1, r_err_and_out, yyvsp[0].word); ;
  987.     break;}
  988. case 27:
  989. #line 207 "parse.y"
  990. { yyval.redirect = make_redirection ( yyvsp[-2].number, r_input_output, yyvsp[0].word); ;
  991.     break;}
  992. case 28:
  993. #line 209 "parse.y"
  994. {
  995.               REDIRECT *t1, *t2;
  996.               extern WORD_DESC *copy_word ();
  997.  
  998.               t1 = make_redirection ( 0, r_input_direction, yyvsp[0].word);
  999.               t2 = make_redirection ( 1, r_output_direction, copy_word (yyvsp[0].word));
  1000.               t1->next = t2;
  1001.               yyval.redirect = t1;
  1002.             ;
  1003.     break;}
  1004. case 29:
  1005. #line 219 "parse.y"
  1006. { yyval.redirect = make_redirection ( 1, r_output_force, yyvsp[0].word); ;
  1007.     break;}
  1008. case 30:
  1009. #line 221 "parse.y"
  1010. { yyval.redirect = make_redirection ( yyvsp[-2].number, r_output_force, yyvsp[0].word); ;
  1011.     break;}
  1012. case 31:
  1013. #line 225 "parse.y"
  1014. { yyval.element.word = yyvsp[0].word; yyval.element.redirect = 0; ;
  1015.     break;}
  1016. case 32:
  1017. #line 227 "parse.y"
  1018. { yyval.element.redirect = yyvsp[0].redirect; yyval.element.word = 0; ;
  1019.     break;}
  1020. case 33:
  1021. #line 231 "parse.y"
  1022. {
  1023.               yyval.redirect = yyvsp[0].redirect;
  1024.             ;
  1025.     break;}
  1026. case 34:
  1027. #line 235 "parse.y"
  1028.               register REDIRECT *t = yyvsp[-1].redirect;
  1029.  
  1030.               while (t->next)
  1031.                 t = t->next;
  1032.               t->next = yyvsp[0].redirect; 
  1033.               yyval.redirect = yyvsp[-1].redirect;
  1034.             ;
  1035.     break;}
  1036. case 35:
  1037. #line 246 "parse.y"
  1038. { yyval.command = make_simple_command (yyvsp[0].element, (COMMAND *)NULL); ;
  1039.     break;}
  1040. case 36:
  1041. #line 248 "parse.y"
  1042. { yyval.command = make_simple_command (yyvsp[0].element, yyvsp[-1].command); ;
  1043.     break;}
  1044. case 37:
  1045. #line 252 "parse.y"
  1046. { yyval.command = clean_simple_command (yyvsp[0].command); ;
  1047.     break;}
  1048. case 38:
  1049. #line 255 "parse.y"
  1050. { yyval.command = yyvsp[0].command; ;
  1051.     break;}
  1052. case 39:
  1053. #line 258 "parse.y"
  1054. {
  1055.               yyval.command->redirects = yyvsp[0].redirect;
  1056.               yyval.command = yyvsp[-1].command;
  1057.             ;
  1058.     break;}
  1059. case 40:
  1060. #line 265 "parse.y"
  1061. { yyval.command = make_for_command (yyvsp[-4].word, (WORD_LIST *)add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1062.     break;}
  1063. case 41:
  1064. #line 267 "parse.y"
  1065. { yyval.command = make_for_command (yyvsp[-4].word, (WORD_LIST *)add_string_to_list ("$@", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1066.     break;}
  1067. case 42:
  1068. #line 269 "parse.y"
  1069. { yyval.command = make_for_command (yyvsp[-5].word, (WORD_LIST *)add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1070.     break;}
  1071. case 43:
  1072. #line 271 "parse.y"
  1073. { yyval.command = make_for_command (yyvsp[-5].word, (WORD_LIST *)add_string_to_list ("\"$@\"", (WORD_LIST *)NULL), yyvsp[-1].command); ;
  1074.     break;}
  1075. case 44:
  1076. #line 274 "parse.y"
  1077. { yyval.command = make_for_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command); ;
  1078.     break;}
  1079. case 45:
  1080. #line 276 "parse.y"
  1081. { yyval.command = make_for_command (yyvsp[-8].word, (WORD_LIST *)reverse_list (yyvsp[-5].word_list), yyvsp[-1].command); ;
  1082.     break;}
  1083. case 46:
  1084. #line 279 "parse.y"
  1085. { yyval.command = make_case_command (yyvsp[-4].word, (PATTERN_LIST *)NULL); ;
  1086.     break;}
  1087. case 47:
  1088. #line 281 "parse.y"
  1089. { yyval.command = make_case_command (yyvsp[-5].word, yyvsp[-2].pattern); ;
  1090.     break;}
  1091. case 48:
  1092. #line 283 "parse.y"
  1093. { /* Nobody likes this...
  1094.                  report_syntax_error ("Inserted `;;'"); */
  1095.               yyval.command = make_case_command (yyvsp[-4].word, yyvsp[-1].pattern); ;
  1096.     break;}
  1097. case 49:
  1098. #line 288 "parse.y"
  1099. { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, (COMMAND *)NULL); ;
  1100.     break;}
  1101. case 50:
  1102. #line 290 "parse.y"
  1103. { yyval.command = make_if_command (yyvsp[-5].command, yyvsp[-3].command, yyvsp[-1].command); ;
  1104.     break;}
  1105. case 51:
  1106. #line 292 "parse.y"
  1107. { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[-1].command); ;
  1108.     break;}
  1109. case 52:
  1110. #line 295 "parse.y"
  1111. { yyval.command = make_while_command (yyvsp[-3].command, yyvsp[-1].command); ;
  1112.     break;}
  1113. case 53:
  1114. #line 297 "parse.y"
  1115. { yyval.command = make_until_command (yyvsp[-3].command, yyvsp[-1].command); ;
  1116.     break;}
  1117. case 54:
  1118. #line 300 "parse.y"
  1119. { yyvsp[-1].command->subshell = WANT_SUBSHELL; yyval.command = yyvsp[-1].command; ;
  1120.     break;}
  1121. case 55:
  1122. #line 303 "parse.y"
  1123. { yyval.command = yyvsp[0].command; ;
  1124.     break;}
  1125. case 56:
  1126. #line 306 "parse.y"
  1127. { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
  1128.     break;}
  1129. case 57:
  1130. #line 309 "parse.y"
  1131. { yyval.command = make_function_def (yyvsp[-4].word, yyvsp[0].command); ;
  1132.     break;}
  1133. case 58:
  1134. #line 312 "parse.y"
  1135. { yyval.command = make_function_def (yyvsp[-2].word, yyvsp[0].command); ;
  1136.     break;}
  1137. case 59:
  1138. #line 316 "parse.y"
  1139. { yyval.command = make_group_command (yyvsp[-1].command); ;
  1140.     break;}
  1141. case 60:
  1142. #line 320 "parse.y"
  1143. { yyval.command = make_if_command (yyvsp[-2].command, yyvsp[0].command, (COMMAND *)NULL); ;
  1144.     break;}
  1145. case 61:
  1146. #line 322 "parse.y"
  1147. { yyval.command = make_if_command (yyvsp[-4].command, yyvsp[-2].command, yyvsp[0].command); ;
  1148.     break;}
  1149. case 62:
  1150. #line 324 "parse.y"
  1151. { yyval.command = make_if_command (yyvsp[-3].command, yyvsp[-1].command, yyvsp[0].command); ;
  1152.     break;}
  1153. case 64:
  1154. #line 330 "parse.y"
  1155. { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
  1156.     break;}
  1157. case 65:
  1158. #line 334 "parse.y"
  1159. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, yyvsp[0].command); ;
  1160.     break;}
  1161. case 66:
  1162. #line 336 "parse.y"
  1163. { yyval.pattern = make_pattern_list (yyvsp[-2].word_list, (COMMAND *)NULL); ;
  1164.     break;}
  1165. case 68:
  1166. #line 342 "parse.y"
  1167. { yyvsp[0].pattern->next = yyvsp[-1].pattern; yyval.pattern = yyvsp[0].pattern; ;
  1168.     break;}
  1169. case 69:
  1170. #line 346 "parse.y"
  1171. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, yyvsp[-1].command); ;
  1172.     break;}
  1173. case 70:
  1174. #line 348 "parse.y"
  1175. { yyval.pattern = make_pattern_list (yyvsp[-3].word_list, (COMMAND *)NULL); ;
  1176.     break;}
  1177. case 71:
  1178. #line 352 "parse.y"
  1179. { yyval.word_list = make_word_list (yyvsp[0].word, (WORD_LIST *)NULL); ;
  1180.     break;}
  1181. case 72:
  1182. #line 354 "parse.y"
  1183. { yyval.word_list = make_word_list (yyvsp[0].word, yyvsp[-2].word_list); ;
  1184.     break;}
  1185. case 73:
  1186. #line 363 "parse.y"
  1187. {
  1188.               yyval.command = yyvsp[0].command;
  1189.               if (need_here_doc)
  1190.                 make_here_document (redirection_needing_here_doc);
  1191.               need_here_doc = 0;
  1192.              ;
  1193.     break;}
  1194. case 76:
  1195. #line 374 "parse.y"
  1196. { yyval.command = command_connect (yyvsp[-2].command, 0, '&'); ;
  1197.     break;}
  1198. case 78:
  1199. #line 380 "parse.y"
  1200. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
  1201.     break;}
  1202. case 79:
  1203. #line 382 "parse.y"
  1204. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
  1205.     break;}
  1206. case 80:
  1207. #line 384 "parse.y"
  1208. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '&'); ;
  1209.     break;}
  1210. case 81:
  1211. #line 386 "parse.y"
  1212. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
  1213.     break;}
  1214. case 82:
  1215. #line 388 "parse.y"
  1216. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, ';'); ;
  1217.     break;}
  1218. case 83:
  1219. #line 390 "parse.y"
  1220. { yyval.command = yyvsp[0].command; ;
  1221.     break;}
  1222. case 84:
  1223. #line 392 "parse.y"
  1224. {
  1225.               yyvsp[0].command->invert_pipeline = 1;
  1226.               yyval.command = yyvsp[0].command;
  1227.             ;
  1228.     break;}
  1229. case 90:
  1230. #line 414 "parse.y"
  1231. {
  1232.               yyval.command = yyvsp[0].command;
  1233.               if (need_here_doc)
  1234.                 make_here_document (redirection_needing_here_doc);
  1235.               need_here_doc = 0;
  1236.             ;
  1237.     break;}
  1238. case 91:
  1239. #line 421 "parse.y"
  1240. {
  1241.               yyval.command = command_connect (yyvsp[-1].command, (COMMAND *)NULL, '&');
  1242.               if (need_here_doc)
  1243.                 make_here_document (redirection_needing_here_doc);
  1244.               need_here_doc = 0;
  1245.             ;
  1246.     break;}
  1247. case 92:
  1248. #line 428 "parse.y"
  1249. {
  1250.               yyval.command = yyvsp[-1].command;
  1251.               if (need_here_doc)
  1252.                 make_here_document (redirection_needing_here_doc);
  1253.               need_here_doc = 0;
  1254.             ;
  1255.     break;}
  1256. case 93:
  1257. #line 437 "parse.y"
  1258. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, AND_AND); ;
  1259.     break;}
  1260. case 94:
  1261. #line 439 "parse.y"
  1262. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, OR_OR); ;
  1263.     break;}
  1264. case 95:
  1265. #line 441 "parse.y"
  1266. { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, '&'); ;
  1267.     break;}
  1268. case 96:
  1269. #line 443 "parse.y"
  1270. { yyval.command = command_connect (yyvsp[-2].command, yyvsp[0].command, ';'); ;
  1271.     break;}
  1272. case 97:
  1273. #line 445 "parse.y"
  1274. { yyval.command = yyvsp[0].command; ;
  1275.     break;}
  1276. case 98:
  1277. #line 447 "parse.y"
  1278. {
  1279.               yyvsp[0].command->invert_pipeline = 1;
  1280.               yyval.command = yyvsp[0].command;
  1281.             ;
  1282.     break;}
  1283. case 99:
  1284. #line 455 "parse.y"
  1285. { yyval.command = command_connect (yyvsp[-3].command, yyvsp[0].command, '|'); ;
  1286.     break;}
  1287. case 100:
  1288. #line 457 "parse.y"
  1289. { yyval.command = yyvsp[0].command; ;
  1290.     break;}
  1291. }
  1292.    /* the action file gets copied in in place of this dollarsign */
  1293. #line 423 "/net/acae127/home/bammi/lib/bison.simple"
  1294.  
  1295.   yyvsp -= yylen;
  1296.   yyssp -= yylen;
  1297. #ifdef YYLSP_NEEDED
  1298.   yylsp -= yylen;
  1299. #endif
  1300.  
  1301. #if YYDEBUG != 0
  1302.   if (yydebug)
  1303.     {
  1304.       short *ssp1 = yyss - 1;
  1305.       fprintf (stderr, "state stack now");
  1306.       while (ssp1 != yyssp)
  1307.     fprintf (stderr, " %d", *++ssp1);
  1308.       fprintf (stderr, "\n");
  1309.     }
  1310. #endif
  1311.  
  1312.   *++yyvsp = yyval;
  1313.  
  1314. #ifdef YYLSP_NEEDED
  1315.   yylsp++;
  1316.   if (yylen == 0)
  1317.     {
  1318.       yylsp->first_line = yylloc.first_line;
  1319.       yylsp->first_column = yylloc.first_column;
  1320.       yylsp->last_line = (yylsp-1)->last_line;
  1321.       yylsp->last_column = (yylsp-1)->last_column;
  1322.       yylsp->text = 0;
  1323.     }
  1324.   else
  1325.     {
  1326.       yylsp->last_line = (yylsp+yylen-1)->last_line;
  1327.       yylsp->last_column = (yylsp+yylen-1)->last_column;
  1328.     }
  1329. #endif
  1330.  
  1331.   /* Now "shift" the result of the reduction.
  1332.      Determine what state that goes to,
  1333.      based on the state we popped back to
  1334.      and the rule number reduced by.  */
  1335.  
  1336.   yyn = yyr1[yyn];
  1337.  
  1338.   yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
  1339.   if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
  1340.     yystate = yytable[yystate];
  1341.   else
  1342.     yystate = yydefgoto[yyn - YYNTBASE];
  1343.  
  1344.   goto yynewstate;
  1345.  
  1346. yyerrlab:   /* here on detecting error */
  1347.  
  1348.   if (! yyerrstatus)
  1349.     /* If not already recovering from an error, report this error.  */
  1350.     {
  1351.       ++yynerrs;
  1352.  
  1353. #ifdef YYERROR_VERBOSE
  1354.       yyn = yypact[yystate];
  1355.  
  1356.       if (yyn > YYFLAG && yyn < YYLAST)
  1357.     {
  1358.       int size = 0;
  1359.       char *msg;
  1360.       int x, count;
  1361.  
  1362.       count = 0;
  1363.       for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1364.         if (yycheck[x + yyn] == x)
  1365.           size += strlen(yytname[x]) + 15, count++;
  1366.       msg = (char *) xmalloc(size + 15);
  1367.       strcpy(msg, "parse error");
  1368.  
  1369.       if (count < 5)
  1370.         {
  1371.           count = 0;
  1372.           for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
  1373.         if (yycheck[x + yyn] == x)
  1374.           {
  1375.             strcat(msg, count == 0 ? ", expecting `" : " or `");
  1376.             strcat(msg, yytname[x]);
  1377.             strcat(msg, "'");
  1378.             count++;
  1379.           }
  1380.         }
  1381.       yyerror(msg);
  1382.       free(msg);
  1383.     }
  1384.       else
  1385. #endif /* YYERROR_VERBOSE */
  1386.     yyerror("parse error");
  1387.     }
  1388.  
  1389. yyerrlab1:   /* here on error raised explicitly by an action */
  1390.  
  1391.   if (yyerrstatus == 3)
  1392.     {
  1393.       /* if just tried and failed to reuse lookahead token after an error, discard it.  */
  1394.  
  1395.       /* return failure if at end of input */
  1396.       if (yychar == YYEOF)
  1397.     YYABORT;
  1398.  
  1399. #if YYDEBUG != 0
  1400.       if (yydebug)
  1401.     fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
  1402. #endif
  1403.  
  1404.       yychar = YYEMPTY;
  1405.     }
  1406.  
  1407.   /* Else will try to reuse lookahead token
  1408.      after shifting the error token.  */
  1409.  
  1410.   yyerrstatus = 3;        /* Each real token shifted decrements this */
  1411.  
  1412.   goto yyerrhandle;
  1413.  
  1414. yyerrdefault:  /* current state does not do anything special for the error token. */
  1415.  
  1416. #if 0
  1417.   /* This is wrong; only states that explicitly want error tokens
  1418.      should shift them.  */
  1419.   yyn = yydefact[yystate];  /* If its default is to accept any token, ok.  Otherwise pop it.*/
  1420.   if (yyn) goto yydefault;
  1421. #endif
  1422.  
  1423. yyerrpop:   /* pop the current state because it cannot handle the error token */
  1424.  
  1425.   if (yyssp == yyss) YYABORT;
  1426.   yyvsp--;
  1427.   yystate = *--yyssp;
  1428. #ifdef YYLSP_NEEDED
  1429.   yylsp--;
  1430. #endif
  1431.  
  1432. #if YYDEBUG != 0
  1433.   if (yydebug)
  1434.     {
  1435.       short *ssp1 = yyss - 1;
  1436.       fprintf (stderr, "Error: state stack now");
  1437.       while (ssp1 != yyssp)
  1438.     fprintf (stderr, " %d", *++ssp1);
  1439.       fprintf (stderr, "\n");
  1440.     }
  1441. #endif
  1442.  
  1443. yyerrhandle:
  1444.  
  1445.   yyn = yypact[yystate];
  1446.   if (yyn == YYFLAG)
  1447.     goto yyerrdefault;
  1448.  
  1449.   yyn += YYTERROR;
  1450.   if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
  1451.     goto yyerrdefault;
  1452.  
  1453.   yyn = yytable[yyn];
  1454.   if (yyn < 0)
  1455.     {
  1456.       if (yyn == YYFLAG)
  1457.     goto yyerrpop;
  1458.       yyn = -yyn;
  1459.       goto yyreduce;
  1460.     }
  1461.   else if (yyn == 0)
  1462.     goto yyerrpop;
  1463.  
  1464.   if (yyn == YYFINAL)
  1465.     YYACCEPT;
  1466.  
  1467. #if YYDEBUG != 0
  1468.   if (yydebug)
  1469.     fprintf(stderr, "Shifting error token, ");
  1470. #endif
  1471.  
  1472.   *++yyvsp = yylval;
  1473. #ifdef YYLSP_NEEDED
  1474.   *++yylsp = yylloc;
  1475. #endif
  1476.  
  1477.   yystate = yyn;
  1478.   goto yynewstate;
  1479. }
  1480. #line 459 "parse.y"
  1481.  
  1482.  
  1483. /* Initial size to allocate for tokens, and the
  1484.    amount to grow them by. */
  1485. #define TOKEN_DEFAULT_GROW_SIZE 512
  1486.  
  1487. /* The token currently being read. */
  1488. int current_token = 0;
  1489.  
  1490. /* The last read token, or NULL.  read_token () uses this for context
  1491.    checking. */
  1492. int last_read_token = 0;
  1493.  
  1494. /* The token read prior to last_read_token. */
  1495. int token_before_that = 0;
  1496.  
  1497. /* Global var is non-zero when end of file has been reached. */
  1498. int EOF_Reached = 0;
  1499.  
  1500. /* yy_getc () returns the next available character from input or EOF.
  1501.    yy_ungetc (c) makes `c' the next character to read.
  1502.    init_yy_io (get, unget), makes the function `get' the installed function
  1503.    for getting the next character, and makes `unget' the installed function
  1504.    for un-getting a character. */
  1505. return_EOF ()            /* does nothing good. */
  1506. {
  1507.   return (EOF);
  1508. }
  1509.  
  1510. /* Variables containing the current get and unget functions. */
  1511.  
  1512. /* Some stream `types'. */
  1513. #define st_stream 0
  1514. #define st_string 1
  1515.  
  1516. Function *get_yy_char = return_EOF;
  1517. Function *unget_yy_char = return_EOF;
  1518. int yy_input_type = st_stream;
  1519. FILE *yy_input_dev = (FILE *)NULL;
  1520.  
  1521. /* The current stream name.  In the case of a file, this is a filename. */
  1522. char *stream_name = (char *)NULL;
  1523.  
  1524. /* Function to set get_yy_char and unget_yy_char. */
  1525. init_yy_io (get_function, unget_function, type, location)
  1526.      Function *get_function, *unget_function;
  1527.      int type;
  1528.      FILE *location;
  1529. {
  1530.   get_yy_char = get_function;
  1531.   unget_yy_char = unget_function;
  1532.   yy_input_type = type;
  1533.   yy_input_dev = location;
  1534. }
  1535.  
  1536. /* Call this to get the next character of input. */
  1537. yy_getc ()
  1538. {
  1539.   return (*get_yy_char) ();
  1540. }
  1541.  
  1542. /* Call this to unget C.  That is, to make C the next character
  1543.    to be read. */
  1544. yy_ungetc (c)
  1545. {
  1546.   return (*unget_yy_char) (c);
  1547. }
  1548.  
  1549. /* **************************************************************** */
  1550. /*                                    */
  1551. /*          Let input be read from readline ().            */
  1552. /*                                    */
  1553. /* **************************************************************** */
  1554.  
  1555. #if defined (READLINE)
  1556. char *current_readline_prompt = (char *)NULL;
  1557. char *current_readline_line = (char *)NULL;
  1558. int current_readline_line_index = 0;
  1559.  
  1560. static int readline_initialized_yet = 0;
  1561. int
  1562. yy_readline_get ()
  1563. {
  1564.   if (!current_readline_line)
  1565.     {
  1566.       char *readline ();
  1567.       SigHandler *old_sigint;
  1568.       extern sighandler sigint_sighandler ();
  1569.       extern int interrupt_immediately;
  1570.  
  1571. #if defined (JOB_CONTROL)
  1572.       extern int shell_pgrp, job_control;
  1573. #endif
  1574.  
  1575.       if (!readline_initialized_yet)
  1576.     {
  1577.       initialize_readline ();
  1578.       readline_initialized_yet = 1;
  1579.     }
  1580.  
  1581. #if defined (JOB_CONTROL)
  1582.       if (job_control)
  1583.     give_terminal_to (shell_pgrp);
  1584. #endif /* JOB_CONTROL */
  1585.  
  1586.       old_sigint = (SigHandler *)signal (SIGINT, sigint_sighandler);
  1587.       interrupt_immediately++;
  1588.  
  1589.       if (!current_readline_prompt)
  1590.     current_readline_line = readline ("");
  1591.       else
  1592.     current_readline_line = readline (current_readline_prompt);
  1593.  
  1594.       interrupt_immediately--;
  1595.       signal (SIGINT, old_sigint);
  1596.  
  1597.       /* Reset the prompt to whatever is in the decoded value of
  1598.      prompt_string_pointer. */
  1599.       reset_readline_prompt ();
  1600.  
  1601.       current_readline_line_index = 0;
  1602.  
  1603.       if (!current_readline_line)
  1604.     {
  1605.       current_readline_line_index = 0;
  1606.       return (EOF);
  1607.     }
  1608.  
  1609.       current_readline_line =
  1610.     (char *)xrealloc (current_readline_line,
  1611.               2 + strlen (current_readline_line));
  1612.       strcat (current_readline_line, "\n");
  1613.     }
  1614.  
  1615.   if (!current_readline_line[current_readline_line_index])
  1616.     {
  1617.       free (current_readline_line);
  1618.       current_readline_line = (char *)NULL;
  1619.       return (yy_readline_get ());
  1620.     }
  1621.   else
  1622.     {
  1623.       int c = current_readline_line[current_readline_line_index++];
  1624.       return (c);
  1625.     }
  1626. }
  1627.  
  1628. int
  1629. yy_readline_unget (c)
  1630. {
  1631.   if (current_readline_line_index && current_readline_line)
  1632.     current_readline_line[--current_readline_line_index] = c;
  1633.   return (c);
  1634. }
  1635.   
  1636. with_input_from_stdin ()
  1637. {
  1638.   init_yy_io (yy_readline_get, yy_readline_unget,
  1639.           st_string, (FILE *)current_readline_line);
  1640.   stream_name = savestring ("readline stdin");
  1641. }
  1642.  
  1643. #else  /* !READLINE */
  1644.  
  1645. with_input_from_stdin ()
  1646. {
  1647.   with_input_from_stream (stdin, "stdin");
  1648. }
  1649. #endif    /* !READLINE */
  1650.  
  1651. /* **************************************************************** */
  1652. /*                                    */
  1653. /*   Let input come from STRING.  STRING is zero terminated.        */
  1654. /*                                    */
  1655. /* **************************************************************** */
  1656.  
  1657. int
  1658. yy_string_get ()
  1659. {
  1660.   /* If the string doesn't exist, or is empty, EOF found. */
  1661.   if (!(char *)yy_input_dev || !*(char *)yy_input_dev)
  1662.     return (EOF);
  1663.   else
  1664.     {
  1665.       register char *temp = (char *)yy_input_dev;
  1666.       int c = *temp++;
  1667.       yy_input_dev = (FILE *)temp;
  1668.       return (c);
  1669.     }
  1670. }
  1671.  
  1672. int
  1673. yy_string_unget (c)
  1674.      int c;
  1675. {
  1676.   register char *temp = (char *)yy_input_dev;
  1677.   *(--temp) = c;
  1678.   yy_input_dev = (FILE *)temp;
  1679.   return (c);
  1680. }
  1681.  
  1682. with_input_from_string (string, name)
  1683.      char *string;
  1684.      char *name;
  1685. {
  1686.   init_yy_io (yy_string_get, yy_string_unget, st_string, (FILE *)string);
  1687.   stream_name = savestring (name);
  1688. }
  1689.  
  1690. /* **************************************************************** */
  1691. /*                                    */
  1692. /*             Let input come from STREAM.            */
  1693. /*                                    */
  1694. /* **************************************************************** */
  1695.  
  1696. #if defined(atarist)
  1697. extern int console_read_byte();
  1698. #endif
  1699.  
  1700. int
  1701. yy_stream_get ()
  1702. {
  1703.   if (yy_input_dev)
  1704. #if defined (USG)
  1705.     return (sysv_getc (yy_input_dev));
  1706. #else
  1707. /**
  1708.  ** (sjk)++ Atari ST hack for input
  1709.  **/
  1710. #if !defined(atarist)
  1711.     return (getc (yy_input_dev));
  1712. #else 
  1713.     return(console_read_byte(fileno(yy_input_dev)));
  1714. #endif 
  1715. #endif    /* USG */
  1716.   else return (EOF);
  1717. }
  1718.  
  1719. int
  1720. yy_stream_unget (c)
  1721.      int c;
  1722. {
  1723.   return (ungetc (c, yy_input_dev));
  1724. }
  1725.  
  1726. with_input_from_stream (stream, name)
  1727.      FILE *stream;
  1728.      char *name;
  1729. {
  1730.   init_yy_io (yy_stream_get, yy_stream_unget, st_stream, stream);
  1731.   stream_name = savestring (name);
  1732. }
  1733.  
  1734. typedef struct stream_saver {
  1735.   struct stream_saver *next;
  1736.   Function *getter, *putter;
  1737.   int type, line;
  1738.   char *location, *name;
  1739. } STREAM_SAVER;
  1740.  
  1741. /* The globally known line number. */
  1742. int line_number = 0;
  1743.  
  1744. STREAM_SAVER *stream_list = (STREAM_SAVER *)NULL;
  1745.  
  1746. push_stream ()
  1747. {
  1748.   STREAM_SAVER *temp = (STREAM_SAVER *)xmalloc (sizeof (STREAM_SAVER));
  1749.   temp->type = yy_input_type;
  1750.   temp->location = (char *)yy_input_dev;
  1751.   temp->getter = get_yy_char;
  1752.   temp->putter = unget_yy_char;
  1753.   temp->line = line_number;
  1754.   temp->name = stream_name; stream_name = (char *)NULL;
  1755.   temp->next = stream_list;
  1756.   stream_list = temp;
  1757.   EOF_Reached = line_number = 0;
  1758. }
  1759.  
  1760. pop_stream ()
  1761. {
  1762.   if (!stream_list)
  1763.     {
  1764.       EOF_Reached = 1;
  1765.     }
  1766.   else
  1767.     {
  1768.       STREAM_SAVER *temp = stream_list;
  1769.     
  1770.       EOF_Reached = 0;
  1771.       stream_list = stream_list->next;
  1772.  
  1773.       if (stream_name)
  1774.     free (stream_name);
  1775.       stream_name = temp->name;
  1776.  
  1777.       init_yy_io (temp->getter, temp->putter, temp->type, (FILE *)temp->location);
  1778.       line_number = temp->line;
  1779.       free (temp);
  1780.     }
  1781. }
  1782.  
  1783. /*
  1784.  * This is used to inhibit alias expansion and reserved word recognition
  1785.  * inside case statement pattern lists.     A `case statement pattern list'
  1786.  * is:
  1787.  *    everything between the `in' in a `case word in' and the next ')'
  1788.  *    or `esac'
  1789.  *    everything between a `;;' and the next `)' or `esac'
  1790.  */
  1791. static int in_case_pattern_list = 0;
  1792.  
  1793. #if defined (ALIAS)
  1794. /*
  1795.  * Pseudo-global variables used in implementing token-wise alias expansion.
  1796.  */
  1797.  
  1798. static int expand_next_token = 0;
  1799. static char *current_token_being_expanded = (char *)NULL;
  1800. static char *pending_token_being_expanded = (char *)NULL;
  1801.  
  1802. /*
  1803.  * Pushing and popping strings.     This works together with shell_getc to 
  1804.  * implement alias expansion on a per-token basis.
  1805.  */
  1806.  
  1807. typedef struct string_saver {
  1808.   struct string_saver *next;
  1809.   int expand_alias;  /* value to set expand_alias to when string is popped */
  1810.   char *saved_line;
  1811.   int saved_line_size, saved_line_index, saved_line_terminator;
  1812.   char *saved_token_being_expanded;
  1813. } STRING_SAVER;
  1814.  
  1815. STRING_SAVER *pushed_string_list = (STRING_SAVER *)NULL;
  1816.  
  1817. static void save_expansion ();
  1818.  
  1819. /*
  1820.  * Push the current shell_input_line onto a stack of such lines and make S
  1821.  * the current input.  Used when expanding aliases.  EXPAND is used to set
  1822.  * the value of expand_next_token when the string is popped, so that the
  1823.  * word after the alias in the original line is handled correctly when the
  1824.  * alias expands to multiple words.  TOKEN is the token that was expanded
  1825.  * into S; it is saved and used to prevent infinite recursive expansion.
  1826.  */
  1827. static void
  1828. push_string (s, expand, token)
  1829.      char *s;
  1830.      int expand;
  1831.      char *token;
  1832. {
  1833.   extern char *shell_input_line;
  1834.   extern int shell_input_line_size, shell_input_line_index,
  1835.          shell_input_line_terminator;
  1836.   STRING_SAVER *temp = (STRING_SAVER *) xmalloc (sizeof (STRING_SAVER));
  1837.  
  1838.   temp->expand_alias = expand;
  1839.   temp->saved_line = shell_input_line;
  1840.   temp->saved_line_size = shell_input_line_size;
  1841.   temp->saved_line_index = shell_input_line_index;
  1842.   temp->saved_line_terminator = shell_input_line_terminator;
  1843.   temp->saved_token_being_expanded = current_token_being_expanded;
  1844.   temp->next = pushed_string_list;
  1845.   pushed_string_list = temp;
  1846.  
  1847.   save_expansion (token);
  1848.  
  1849.   current_token_being_expanded = token;
  1850.   shell_input_line = s;
  1851.   shell_input_line_size = strlen (s);
  1852.   shell_input_line_index = 0;
  1853.   shell_input_line_terminator = '\0';
  1854.   expand_next_token = 0;
  1855. }
  1856.  
  1857. /*
  1858.  * Make the top of the pushed_string stack be the current shell input.
  1859.  * Only called when there is something on the stack.  Called from shell_getc
  1860.  * when it thinks it has consumed the string generated by an alias expansion
  1861.  * and needs to return to the original input line.
  1862.  */
  1863. static void
  1864. pop_string ()
  1865. {
  1866.   extern char *shell_input_line;
  1867.   extern int shell_input_line_size, shell_input_line_index,
  1868.          shell_input_line_terminator;
  1869.   STRING_SAVER *t;
  1870.  
  1871.   if (shell_input_line)
  1872.     free (shell_input_line);
  1873.   shell_input_line = pushed_string_list->saved_line;
  1874.   shell_input_line_index = pushed_string_list->saved_line_index;
  1875.   shell_input_line_size = pushed_string_list->saved_line_size;
  1876.   shell_input_line_terminator = pushed_string_list->saved_line_terminator;
  1877.   expand_next_token = pushed_string_list->expand_alias;
  1878.   pending_token_being_expanded = pushed_string_list->saved_token_being_expanded;
  1879.   t = pushed_string_list;
  1880.   pushed_string_list = pushed_string_list->next;
  1881.   free((char *)t);
  1882. }
  1883.  
  1884. static void
  1885. free_string_list ()
  1886. {
  1887.   register STRING_SAVER *t = pushed_string_list, *t1;
  1888.  
  1889.   while (t)
  1890.     {
  1891.       t1 = t->next;
  1892.       if (t->saved_line)
  1893.     free (t->saved_line);
  1894.       if (t->saved_token_being_expanded)
  1895.     free (t->saved_token_being_expanded);
  1896.       free ((char *)t);
  1897.       t = t1;
  1898.     }
  1899.   pushed_string_list = (STRING_SAVER *)NULL;
  1900. }
  1901.  
  1902. /* This is a stack to save the values of all tokens for which alias
  1903.    expansion has been performed during the current call to read_token ().
  1904.    It is used to prevent alias expansion loops:
  1905.  
  1906.       alias foo=bar
  1907.       alias bar=baz
  1908.       alias baz=foo
  1909.  
  1910.    Ideally this would be taken care of by push and pop string, but because
  1911.    of when strings are popped the stack will not contain the correct
  1912.    strings to test against.  (The popping is done in shell_getc, so that when
  1913.    the current string is exhausted, shell_getc can simply pop that string off
  1914.    the stack, restore the previous string, and continue with the character
  1915.    following the token whose expansion was originally pushed on the stack.)
  1916.  
  1917.    What we really want is a record of all tokens that have been expanded for
  1918.    aliases during the `current' call to read_token().  This does that, at the
  1919.    cost of being somewhat special-purpose (OK, OK vile and unclean).  Brian,
  1920.    you had better rewrite this whole piece of garbage before the next version
  1921.    is released.
  1922. */
  1923.  
  1924. typedef struct _exp_saver {
  1925.       struct _exp_saver *next;
  1926.       char *saved_token;
  1927. } EXPANSION_SAVER;
  1928.  
  1929. EXPANSION_SAVER *expanded_token_stack = (EXPANSION_SAVER *)NULL;
  1930.  
  1931. static void
  1932. save_expansion (s)
  1933.      char *s;
  1934. {
  1935.   EXPANSION_SAVER *t;
  1936.  
  1937.   t = (EXPANSION_SAVER *) xmalloc (sizeof (EXPANSION_SAVER));
  1938.   t->saved_token = savestring (s);
  1939.   t->next = expanded_token_stack;
  1940.   expanded_token_stack = t;
  1941. }
  1942.  
  1943. /*
  1944.  * Return 1 if TOKEN has already been expanded in the current `stack' of
  1945.  * expansions.    If it has been expanded already, it will appear as the value
  1946.  * of saved_token for some entry in the stack of expansions created for the
  1947.  * current token being expanded.
  1948.  */
  1949. static int
  1950. token_has_been_expanded (token)
  1951.      char *token;
  1952. {
  1953.   register EXPANSION_SAVER *t = expanded_token_stack;
  1954.  
  1955.   while (t)
  1956.     {
  1957.       if (STREQ (token, t->saved_token))
  1958.     return (1);
  1959.       t = t->next;
  1960.     }
  1961.   return (0);
  1962. }
  1963.  
  1964. static void
  1965. free_expansion_stack ()
  1966. {
  1967.   register EXPANSION_SAVER *t = expanded_token_stack, *t1;
  1968.  
  1969.   while (t)
  1970.     {
  1971.       t1 = t->next;
  1972.       free (t->saved_token);
  1973.       free (t);
  1974.       t = t1;
  1975.     }
  1976.   expanded_token_stack = (EXPANSION_SAVER *)NULL;
  1977. }
  1978.  
  1979. #endif /* ALIAS */
  1980.  
  1981. /* Return a line of text, taken from wherever yylex () reads input.
  1982.    If there is no more input, then we return NULL. */
  1983. char *
  1984. read_a_line ()
  1985. {
  1986.   char *line_buffer = (char *)NULL;
  1987.   int indx = 0, buffer_size = 0;
  1988.   int c;
  1989.  
  1990.   while (1)
  1991.     {
  1992.       c = yy_getc ();
  1993.  
  1994.       if (c == 0)
  1995.     continue;
  1996.  
  1997.       /* If there is no more input, then we return NULL. */
  1998.       if (c == EOF)
  1999.     {
  2000.       c = '\n';
  2001.       if (!line_buffer)
  2002.         return ((char *)NULL);
  2003.     }
  2004.  
  2005.       /* `+2' in case the final (200'th) character in the buffer is a newline;
  2006.      otherwise the code below that NULL-terminates it will write over the
  2007.      201st slot and kill the range checking in free(). */
  2008.       if (indx + 2 > buffer_size)
  2009.     if (!buffer_size)
  2010.       line_buffer = (char *)xmalloc (buffer_size = 200);
  2011.     else
  2012.       line_buffer = (char *)xrealloc (line_buffer, buffer_size += 200);
  2013.  
  2014.       line_buffer[indx++] = c;
  2015.       if (c == '\n')
  2016.     {
  2017.       line_buffer[indx] = '\0';
  2018.       return (line_buffer);
  2019.     }
  2020.     }
  2021. }
  2022.  
  2023. /* Return a line as in read_a_line (), but insure that the prompt is
  2024.    the secondary prompt. */
  2025. char *
  2026. read_secondary_line ()
  2027. {
  2028.   prompt_string_pointer = &ps2_prompt;
  2029.   prompt_again ();
  2030.   return (read_a_line ());
  2031. }
  2032.  
  2033.  
  2034. /* **************************************************************** */
  2035. /*                                    */
  2036. /*                YYLEX ()                */
  2037. /*                                    */
  2038. /* **************************************************************** */
  2039.  
  2040. /* Reserved words.  These are only recognized as the first word of a
  2041.    command.  TOKEN_WORD_ALIST. */
  2042. struct {
  2043.   char *word;
  2044.   int token;
  2045. } token_word_alist[] = {
  2046.   {"if", IF},
  2047.   {"then", THEN},
  2048.   {"else", ELSE},
  2049.   {"elif", ELIF},
  2050.   {"fi", FI},
  2051.   {"case", CASE},
  2052.   {"esac", ESAC},
  2053.   {"for", FOR},
  2054.   {"while", WHILE},
  2055.   {"until", UNTIL},
  2056.   {"do", DO},
  2057.   {"done", DONE},
  2058.   {"in", IN},
  2059.   {"function", FUNCTION},
  2060.   {"{", '{'},
  2061.   {"}", '}'},
  2062.   {"!", BANG},
  2063.   {(char *)NULL, 0}
  2064. };
  2065.  
  2066. /* Where shell input comes from.  History expansion is performed on each
  2067.    line, when the shell is interactive. */
  2068. char *shell_input_line = (char *)NULL;
  2069. int shell_input_line_index = 0;
  2070. int shell_input_line_size = 0;    /* amount allocated for shell_input_line */
  2071. int shell_input_line_len = 0;    /* strlen (shell_input_line) */
  2072.  
  2073. /* Either zero, or EOF. */
  2074. int shell_input_line_terminator = 0;
  2075.  
  2076. /* Return the next shell input character.  This always reads characters
  2077.    from shell_input_line; when that line is exhausted, it is time to
  2078.    read the next line. */
  2079. int
  2080. shell_getc (remove_quoted_newline)
  2081.      int remove_quoted_newline;
  2082. {
  2083.   extern int login_shell;
  2084.   int c;
  2085.  
  2086.   QUIT;    /* XXX this is experimental */
  2087.  
  2088. #if defined (ALIAS)
  2089.   /* If shell_input_line[shell_input_line_index] == 0, but there is
  2090.      something on the pushed list of strings, then we don't want to go
  2091.      off and get another line.    We let the code down below handle it. */
  2092.  
  2093.   if (!shell_input_line || ((!shell_input_line[shell_input_line_index]) &&
  2094.                 (pushed_string_list == (STRING_SAVER *)NULL)))
  2095. #else /* !ALIAS */
  2096.   if (!shell_input_line || !shell_input_line[shell_input_line_index])
  2097. #endif /* !ALIAS */
  2098.     {
  2099.       register int i, l;
  2100.       char *pre_process_line (), *expansions;
  2101.  
  2102.       restart_read_next_line:
  2103.  
  2104.       line_number++;
  2105.  
  2106.     restart_read:
  2107.  
  2108.       QUIT;    /* XXX experimental */
  2109.  
  2110.       i = 0;
  2111.       shell_input_line_terminator = 0;
  2112.  
  2113. #if defined (JOB_CONTROL)
  2114.       notify_and_cleanup ();
  2115. #endif
  2116.  
  2117.       clearerr (stdin);
  2118.       while (c = yy_getc ())
  2119.     {
  2120.       if (i + 2 > shell_input_line_size)
  2121.         shell_input_line = (char *)
  2122.           xrealloc (shell_input_line, shell_input_line_size += 256);
  2123.  
  2124.       if (c == EOF)
  2125.         {
  2126.           clearerr (stdin);
  2127.  
  2128.           if (!i)
  2129.         shell_input_line_terminator = EOF;
  2130.  
  2131.           shell_input_line[i] = '\0';
  2132.           break;
  2133.         }
  2134.  
  2135.       shell_input_line[i++] = c;
  2136.  
  2137.       if (c == '\n')
  2138.         {
  2139.           shell_input_line[--i] = '\0';
  2140.           break;
  2141.         }
  2142.     }
  2143.       shell_input_line_index = 0;
  2144.       shell_input_line_len = i;        /* == strlen (shell_input_line) */
  2145.  
  2146.       if (!shell_input_line[0])
  2147.     goto after_pre_process;
  2148.  
  2149.       if (interactive)
  2150.     {
  2151.       expansions = pre_process_line (shell_input_line, 1, 1);
  2152.  
  2153.       free (shell_input_line);
  2154.       shell_input_line = expansions;
  2155.       shell_input_line_len = shell_input_line ?
  2156.                  strlen (shell_input_line) :
  2157.                  0;
  2158.       /* We have to force the xrealloc below because we don't know the
  2159.          true allocated size of shell_input_line anymore. */
  2160.       shell_input_line_size = shell_input_line_len;
  2161.     }
  2162.  
  2163.   after_pre_process:
  2164.       if (shell_input_line)
  2165.     {
  2166.       if (echo_input_at_read)
  2167.         fprintf (stderr, "%s\n", shell_input_line);
  2168.     }
  2169.       else
  2170.     {
  2171.       shell_input_line_size = 0;
  2172.       prompt_string_pointer = ¤t_prompt_string;
  2173.       prompt_again ();
  2174.       goto restart_read;
  2175.     }
  2176.  
  2177.       /* Add the newline to the end of this string, iff the string does
  2178.      not already end in an EOF character.  */
  2179.       if (shell_input_line_terminator != EOF)
  2180.     {
  2181.       l = shell_input_line_len;    /* was a call to strlen */
  2182.  
  2183.       if (l + 3 > shell_input_line_size)
  2184.         shell_input_line = (char *)xrealloc (shell_input_line,
  2185.                     1 + (shell_input_line_size += 2));
  2186.  
  2187.       strcpy (shell_input_line + l, "\n");
  2188.     }
  2189.     }
  2190.   
  2191.   c = shell_input_line[shell_input_line_index];
  2192.  
  2193.   if (c)
  2194.     shell_input_line_index++;
  2195.  
  2196.   if (c == '\\' && remove_quoted_newline &&
  2197.       shell_input_line[shell_input_line_index] == '\n')
  2198.     {
  2199.     prompt_again ();
  2200.     goto restart_read_next_line;
  2201.     }
  2202.  
  2203. #if defined (ALIAS)
  2204.   /*
  2205.    * If c is NULL, we have reached the end of the current input string.     If
  2206.    * pushed_string_list is non-empty, it's time to pop to the previous string
  2207.    * because we have fully consumed the result of the last alias expansion.
  2208.    * Do it transparently; just return the next character of the string popped
  2209.    * to.  We need to hang onto current_token_being_expanded until the token
  2210.    * currently being read has been recognized; we can't restore it in
  2211.    * pop_string () because the token currently being read would be
  2212.    * inappropriately compared with it.    We defer restoration until the next
  2213.    * call to read_token ().
  2214.    */
  2215.  
  2216.   if (!c && (pushed_string_list != (STRING_SAVER *)NULL))
  2217.     {
  2218.       pop_string ();
  2219.       c = shell_input_line[shell_input_line_index];
  2220.       if (c)
  2221.     shell_input_line_index++;
  2222.     }
  2223. #endif /* ALIAS */
  2224.  
  2225.   if (!c && shell_input_line_terminator == EOF)
  2226.     {
  2227.       if (shell_input_line_index != 0)
  2228.     return ('\n');
  2229.       else
  2230.     return (EOF);
  2231.     }
  2232.  
  2233.   return (c);
  2234. }
  2235.  
  2236. /* Put C back into the input for the shell. */
  2237. shell_ungetc (c)
  2238.      int c;
  2239. {
  2240.   if (shell_input_line && shell_input_line_index)
  2241.     shell_input_line[--shell_input_line_index] = c;
  2242. }
  2243.  
  2244. /* Discard input until CHARACTER is seen. */
  2245. discard_until (character)
  2246.      int character;
  2247. {
  2248.   int c;
  2249.   while ((c = shell_getc (0)) != EOF && c != character)
  2250.     ;
  2251.   if (c != EOF )
  2252.     shell_ungetc (c);
  2253. }
  2254.  
  2255. #if defined (HISTORY_REDITING)
  2256. /* Tell readline () that we have some text for it to edit. */
  2257. re_edit (text)
  2258.      char *text;
  2259. {
  2260. #if defined (READLINE)
  2261.   if (strcmp (stream_name, "readline stdin") == 0)
  2262.     bash_re_edit (text);
  2263. #endif /* READLINE */
  2264. }
  2265. #endif /* HISTORY_REDITING */
  2266.  
  2267. /* Non-zero means do no history expansion on this line, regardless
  2268.    of what history_expansion says. */
  2269. int history_expansion_inhibited = 0;
  2270.  
  2271. /* Do pre-processing on LINE.  If PRINT_CHANGES is non-zero, then
  2272.    print the results of expanding the line if there were any changes.
  2273.    If there is an error, return NULL, otherwise the expanded line is
  2274.    returned.  If ADDIT is non-zero the line is added to the history
  2275.    list after history expansion.  ADDIT is just a suggestion;
  2276.    REMEMBER_ON_HISTORY can veto, and does.
  2277.    Right now this does history expansion. */
  2278. char *
  2279. pre_process_line (line, print_changes, addit)
  2280.      char *line;
  2281.      int print_changes, addit;
  2282. {
  2283.   char *return_value = line;
  2284.   int expanded = 0;
  2285.  
  2286.   extern int history_expansion;
  2287.   extern int remember_on_history;
  2288.   int history_expand ();
  2289.   char *history_value;
  2290.  
  2291.   /* History expand the line.  If this results in no errors, then
  2292.      add that line to the history if ADDIT is non-zero. */
  2293.   if (!history_expansion_inhibited && history_expansion)
  2294.     {
  2295.       expanded = history_expand (line, &history_value);
  2296.  
  2297.       if (expanded)
  2298.     {
  2299.       if (print_changes)
  2300.         fprintf (stderr, "%s\n", history_value);
  2301.  
  2302.       /* If there was an error, return NULL. */
  2303.       if (expanded < 0)
  2304.         {
  2305.           free (history_value);
  2306.  
  2307. #if defined (HISTORY_REDITING)
  2308.           /* New hack.  We can allow the user to edit the
  2309.          failed history expansion. */
  2310.           re_edit (line);
  2311. #endif /* HISTORY_REDITING */
  2312.           return ((char *)NULL);
  2313.         }
  2314.     }
  2315.  
  2316.       /* Let other expansions know that return_value can be free'ed,
  2317.      and that a line has been added to the history list.  Note
  2318.      that we only add lines that have something in them. */
  2319.       expanded = 1;
  2320.       return_value = history_value;
  2321.     }
  2322.  
  2323.   if (addit && remember_on_history && *return_value)
  2324.     {
  2325.       extern int history_control;
  2326.       extern int history_lines_this_session;
  2327.  
  2328.       switch (history_control)
  2329.     {
  2330.       case 0:
  2331.         add_history (return_value);
  2332.         history_lines_this_session++;
  2333.         break;
  2334.       case 1:
  2335.         if (*return_value != ' ')
  2336.           {
  2337.         add_history (return_value);
  2338.         history_lines_this_session++;
  2339.           }
  2340.         break;
  2341.       case 2:
  2342.         {
  2343.           HIST_ENTRY *temp;
  2344.  
  2345.           using_history ();
  2346.           temp = previous_history ();
  2347.           if (!temp || (strcmp (temp->line, return_value) != 0))
  2348.         {
  2349.           add_history (return_value);
  2350.           history_lines_this_session++;
  2351.         }
  2352.           using_history ();
  2353.         }
  2354.         break;
  2355.     }
  2356.     }
  2357.  
  2358.   if (!expanded)
  2359.     return_value = savestring (line);
  2360.  
  2361.   return (return_value);
  2362. }
  2363.  
  2364.  
  2365. /* Place to remember the token.     We try to keep the buffer
  2366.    at a reasonable size, but it can grow. */
  2367. char *token = (char *)NULL;
  2368.  
  2369. /* Current size of the token buffer. */
  2370. int token_buffer_size = 0;
  2371.  
  2372. /* Command to read_token () explaining what we want it to do. */
  2373. #define READ 0
  2374. #define RESET 1
  2375. #define prompt_is_ps1 \
  2376.       (!prompt_string_pointer || prompt_string_pointer == &ps1_prompt)
  2377.  
  2378. /* Function for yyparse to call.  yylex keeps track of
  2379.    the last two tokens read, and calls read_token.  */
  2380.  
  2381. yylex ()
  2382. {
  2383.   if (interactive && (!current_token || current_token == '\n'))
  2384.     {
  2385.  
  2386. /**
  2387.  ** (sjk)++
  2388.  **/
  2389. #if !defined(atarist)
  2390.       /* Before we print a prompt, we might have to check mailboxes.
  2391.      We do this only if it is time to do so. Notice that only here
  2392.      is the mail alarm reset; nothing takes place in check_mail ()
  2393.      except the checking of mail.  Please don't change this. */
  2394.       if (prompt_is_ps1 && time_to_check_mail ())
  2395.     {
  2396.       check_mail ();
  2397.       reset_mail_timer ();
  2398.     }
  2399. #endif
  2400.  
  2401.       /* Allow the execution of a random command just before the printing
  2402.      of each primary prompt.  If the shell variable PROMPT_COMMAND
  2403.      is set then the value of it is the command to execute. */
  2404.       if (prompt_is_ps1)
  2405.     {
  2406.       char *command_to_execute = get_string_value ("PROMPT_COMMAND");
  2407.  
  2408.       if (command_to_execute)
  2409.         {
  2410.           extern Function *last_shell_builtin, *this_shell_builtin;
  2411.           extern int last_command_exit_value;
  2412.           Function *temp_last, *temp_this;
  2413.           int temp_exit_value, temp_eof_encountered;
  2414.  
  2415.           temp_last = last_shell_builtin;
  2416.           temp_this = this_shell_builtin;
  2417.           temp_exit_value = last_command_exit_value;
  2418.           temp_eof_encountered = eof_encountered;
  2419.  
  2420.           parse_and_execute
  2421.         (savestring (command_to_execute), "PROMPT_COMMAND");
  2422.  
  2423.           last_shell_builtin = temp_last;
  2424.           this_shell_builtin = temp_this;
  2425.           last_command_exit_value = temp_exit_value;
  2426.           eof_encountered = temp_eof_encountered;
  2427.         }
  2428.     }
  2429.       prompt_again ();
  2430.     }
  2431.  
  2432.   token_before_that = last_read_token;
  2433.   last_read_token = current_token;
  2434.   current_token = read_token (READ);
  2435.   return (current_token);
  2436. }
  2437.  
  2438. /* Called from shell.c when Control-C is typed at top level.  Or
  2439.    by the error rule at top level. */
  2440. reset_parser ()
  2441. {
  2442.   read_token (RESET);
  2443. }
  2444.   
  2445. /* When non-zero, we have read the required tokens
  2446.    which allow ESAC to be the next one read. */
  2447. static int allow_esac_as_next = 0;
  2448.  
  2449. /* When non-zero, accept single '{' as a token itself. */
  2450. static int allow_open_brace = 0;
  2451.  
  2452. /* DELIMITER is the value of the delimiter that is currently
  2453.    enclosing, or zero for none. */
  2454. static int delimiter = 0;
  2455. static int old_delimiter = 0;
  2456.  
  2457. /* When non-zero, an open-brace used to create a group is awaiting a close
  2458.    brace partner. */
  2459. static int open_brace_awaiting_satisfaction = 0;
  2460.  
  2461. /* If non-zero, it is the token that we want read_token to return regardless
  2462.    of what text is (or isn't) present to be read.  read_token resets this. */
  2463. int token_to_read = 0;
  2464.  
  2465. /* Read the next token.     Command can be READ (normal operation) or 
  2466.    RESET (to normalize state). */
  2467. read_token (command)
  2468.      int command;
  2469. {
  2470.   extern int interactive_shell;    /* Whether the current shell is interactive. */
  2471.   int character;        /* Current character. */
  2472.   int peek_char;        /* Temporary look-ahead character. */
  2473.   int result;            /* The thing to return. */
  2474.   WORD_DESC *the_word;        /* The value for YYLVAL when a WORD is read. */
  2475.  
  2476.   if (token_buffer_size < TOKEN_DEFAULT_GROW_SIZE)
  2477.     {
  2478.       if (token)
  2479.     free (token);
  2480.       token = (char *)xmalloc (token_buffer_size = TOKEN_DEFAULT_GROW_SIZE);
  2481.     }
  2482.  
  2483.   if (command == RESET)
  2484.     {
  2485.       delimiter = old_delimiter = 0;
  2486.       open_brace_awaiting_satisfaction = 0;
  2487.       in_case_pattern_list = 0;
  2488.  
  2489. #if defined (ALIAS)
  2490.       if (pushed_string_list)
  2491.     {
  2492.       free_string_list ();
  2493.       pushed_string_list = (STRING_SAVER *)NULL;
  2494.     }
  2495.       if (pending_token_being_expanded)
  2496.     {
  2497.       free (pending_token_being_expanded);
  2498.       pending_token_being_expanded = (char *)NULL;
  2499.     }
  2500.       if (current_token_being_expanded)
  2501.     {
  2502.       free (current_token_being_expanded);
  2503.       current_token_being_expanded = (char *)NULL;
  2504.     }
  2505.  
  2506.       if (expanded_token_stack)
  2507.     {
  2508.       free_expansion_stack ();
  2509.       expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2510.     }
  2511. #endif /* ALIAS */
  2512.  
  2513.       if (shell_input_line)
  2514.     {
  2515.       free (shell_input_line);
  2516.       shell_input_line = (char *)NULL;
  2517.       shell_input_line_size = shell_input_line_index = 0;
  2518.     }
  2519.       last_read_token = '\n';
  2520.       token_to_read = '\n';
  2521.       return;
  2522.     }
  2523.  
  2524.   if (token_to_read)
  2525.     {
  2526.       int rt = token_to_read;
  2527.       token_to_read = 0;
  2528.       return (rt);
  2529.     }
  2530.  
  2531. #if defined (ALIAS)
  2532.   /*
  2533.    * Now we can replace current_token_being_expanded with 
  2534.    * pending_token_being_expanded, since the token that would be 
  2535.    * inappropriately compared has already been returned.
  2536.    *
  2537.    * To see why restoring current_token_being_expanded in pop_string ()
  2538.    * could be a problem, consider "alias foo=foo".  Then try to
  2539.    * expand `foo'.  The initial value of current_token_being_expanded is
  2540.    * NULL, so that is what is pushed onto pushed_string_list as the
  2541.    * value of saved_token_being_expanded.  "foo" then becomes shell_input_line.
  2542.    * read_token calls shell_getc for `f', `o', `o', and then shell_getc
  2543.    * hits the end of shell_input_line.    pushed_string_list is not empty
  2544.    * so it gets popped.     If we were to blindly restore
  2545.    * current_token_being_expanded at this point, `foo' would be compared
  2546.    * with a NULL string in the check for recursive expansion, and would
  2547.    * infinitely recurse.
  2548.    */
  2549.   if (pending_token_being_expanded)
  2550.     {
  2551.       if (current_token_being_expanded)
  2552.     free (current_token_being_expanded);
  2553.       current_token_being_expanded = pending_token_being_expanded;
  2554.       pending_token_being_expanded = (char *)NULL;
  2555.     }
  2556.  
  2557.   /* If we hit read_token () and there are no saved strings on the
  2558.      pushed_string_list, then we are no longer currently expanding a
  2559.      token.  This can't be done in pop_stream, because pop_stream
  2560.      may pop the stream before the current token has finished being
  2561.      completely expanded (consider what happens when we alias foo to foo,
  2562.      and then try to expand it). */
  2563.   if (!pushed_string_list && current_token_being_expanded)
  2564.     {
  2565.       free (current_token_being_expanded);
  2566.       current_token_being_expanded = (char *)NULL;
  2567.  
  2568.       if (expanded_token_stack)
  2569.     {
  2570.       free_expansion_stack ();
  2571.       expanded_token_stack = (EXPANSION_SAVER *)NULL;
  2572.     }
  2573.     }
  2574.  
  2575.   /* This is a place to jump back to once we have successfully expanded a
  2576.      token with an alias and pushed the string with push_string () */
  2577. re_read_token:
  2578.  
  2579. #endif /* ALIAS */
  2580.  
  2581.   /* Read a single word from input.  Start by skipping blanks. */
  2582.   while ((character = shell_getc (1)) != EOF && whitespace (character));
  2583.  
  2584.   if (character == EOF)
  2585.     return (yacc_EOF);
  2586.  
  2587.   if (character == '#' && !interactive)
  2588.     {
  2589.       /* A comment.  Discard until EOL or EOF, and then return a newline. */
  2590.       discard_until ('\n');
  2591.       shell_getc (0);
  2592.  
  2593.       /* If we're about to return an unquoted newline, we can go and collect
  2594.      the text of any pending here document. */
  2595.       if (need_here_doc)
  2596.     make_here_document (redirection_needing_here_doc);
  2597.       need_here_doc = 0;
  2598.  
  2599.       return ('\n');
  2600.     }
  2601.  
  2602.   if (character == '\n')
  2603.     {
  2604.       /* If we're about to return an unquoted newline, we can go and collect
  2605.      the text of any pending here document. */
  2606.       if (need_here_doc)
  2607.     make_here_document (redirection_needing_here_doc);
  2608.       need_here_doc = 0;
  2609.  
  2610.       return (character);
  2611.     }
  2612.  
  2613.   if (member (character, "()<>;&|"))
  2614.     {
  2615.       /* Please note that the shell does not allow whitespace to
  2616.      appear in between tokens which are character pairs, such as
  2617.      "<<" or ">>".    I believe this is the correct behaviour. */
  2618.  
  2619.       if (character == (peek_char = shell_getc (1)))
  2620.     {
  2621.       switch (character)
  2622.         {
  2623.           /* If '<' then we could be at "<<" or at "<<-".  We have to
  2624.          look ahead one more character. */
  2625.         case '<':
  2626.           peek_char = shell_getc (1);
  2627.           if (peek_char == '-')
  2628.         return (LESS_LESS_MINUS);
  2629.           else
  2630.         {
  2631.           shell_ungetc (peek_char);
  2632.           return (LESS_LESS);
  2633.         }
  2634.  
  2635.         case '>': return (GREATER_GREATER);
  2636.         case ';':
  2637.               in_case_pattern_list = 1;
  2638.               return (SEMI_SEMI);
  2639.         case '&': return (AND_AND);
  2640.         case '|': return (OR_OR);
  2641.         }
  2642.     }
  2643.       else
  2644.     {
  2645.       if (peek_char == '&')
  2646.         {
  2647.           switch (character)
  2648.         {
  2649.         case '<': return (LESS_AND);
  2650.         case '>': return (GREATER_AND);
  2651.         }
  2652.         }
  2653.       if (character == '<' && peek_char == '>')
  2654.         return (LESS_GREATER);
  2655.       if (character == '>' && peek_char == '|')
  2656.         return (GREATER_BAR);
  2657.       if (peek_char == '>' && character == '&')
  2658.         return (AND_GREATER);
  2659.     }
  2660.       shell_ungetc (peek_char);
  2661.  
  2662.       /* If we look like we are reading the start of a function
  2663.      definition, then let the reader know about it so that
  2664.      we will do the right thing with `{'. */
  2665.       if (character == ')' &&
  2666.       last_read_token == '(' && token_before_that == WORD)
  2667.     allow_open_brace = 1;
  2668.  
  2669.       if (in_case_pattern_list && (character == ')'))
  2670.     in_case_pattern_list = 0;
  2671.  
  2672.       return (character);
  2673.     }
  2674.  
  2675.   /* Hack <&- (close stdin) case. */
  2676.   if (character == '-')
  2677.     {
  2678.       switch (last_read_token)
  2679.     {
  2680.     case LESS_AND:
  2681.     case GREATER_AND:
  2682.       return (character);
  2683.     }
  2684.     }
  2685.   
  2686.   /* Okay, if we got this far, we have to read a word.    Read one,
  2687.      and then check it against the known ones. */
  2688.   {
  2689.     /* Index into the token that we are building. */
  2690.     int token_index = 0;
  2691.  
  2692.     /* ALL_DIGITS becomes zero when we see a non-digit. */
  2693.     int all_digits = digit (character);
  2694.  
  2695.     /* DOLLAR_PRESENT becomes non-zero if we see a `$'. */
  2696.     int dollar_present = 0;
  2697.  
  2698.     /* QUOTED becomes non-zero if we see one of ("), ('), (`), or (\). */
  2699.     int quoted = 0;
  2700.  
  2701.     /* Non-zero means to ignore the value of the next character, and just
  2702.        to add it no matter what. */
  2703.     int pass_next_character = 0;
  2704.  
  2705.     /* Non-zero means parsing a dollar-paren construct.     It is the count of
  2706.        un-quoted closes we need to see. */
  2707.     int dollar_paren_level = 0;
  2708.  
  2709.     /* Non-zero means parsing a dollar-bracket construct ($[...]).  It is
  2710.        the count of un-quoted `]' characters we need to see. */
  2711.     int dollar_bracket_level = 0;
  2712.  
  2713.     /* Another level variable.    This one is for dollar_parens inside of
  2714.        double-quotes. */
  2715.     int delimited_paren_level = 0;
  2716.  
  2717.     for (;;)
  2718.       {
  2719.     if (character == EOF)
  2720.       goto got_token;
  2721.  
  2722.     if (pass_next_character)
  2723.       {
  2724.         pass_next_character = 0;
  2725.         goto got_character;
  2726.       }
  2727.  
  2728.       if (delimiter && character == '\\' && delimiter != '\'')
  2729.     {
  2730.       peek_char = shell_getc (0);
  2731.       if (peek_char != '\\')
  2732.         shell_ungetc (peek_char);
  2733.       else
  2734.         {
  2735.           token[token_index++] = character;
  2736.           goto got_character;
  2737.         }
  2738.     }
  2739.  
  2740.     /* Handle backslashes.    Quote lots of things when not inside of
  2741.        double-quotes, quote some things inside of double-quotes. */
  2742.        
  2743.     if (character == '\\' && delimiter != '\'')
  2744.       {
  2745.         peek_char = shell_getc (0);
  2746.  
  2747.         /* Backslash-newline is ignored in all cases excepting
  2748.            when quoted with single quotes. */
  2749.         if (peek_char == '\n')
  2750.           {
  2751.         character = '\n';
  2752.         goto next_character;
  2753.           }
  2754.         else
  2755.           {
  2756.         shell_ungetc (peek_char);
  2757.  
  2758.         /* If the next character is to be quoted, do it now. */
  2759.         if (!delimiter || delimiter == '`' ||
  2760.             ((delimiter == '"' ) &&
  2761.              (member (peek_char, slashify_in_quotes))))
  2762.           {
  2763.             pass_next_character++;
  2764.             quoted = 1;
  2765.             goto got_character;
  2766.           }
  2767.           }
  2768.       }
  2769.  
  2770.     /* This is a hack, in its present form.     If a backquote substitution
  2771.        appears within double quotes, everything within the backquotes
  2772.        should be read as part of a single word.  Jesus.  Now I see why
  2773.        Korn introduced the $() form. */
  2774.     if (delimiter && delimiter == '"' && character == '`')
  2775.       {
  2776.         old_delimiter = delimiter;
  2777.         delimiter = character;
  2778.         goto got_character;
  2779.       }
  2780.  
  2781.     if (delimiter)
  2782.       {
  2783.         if (character == delimiter)
  2784.           {
  2785.         if (delimited_paren_level)
  2786.           {
  2787. #if defined (NOTDEF)
  2788.             report_error ("Expected ')' before %c", character);
  2789.             return ('\n');
  2790. #else
  2791.             goto got_character;
  2792. #endif /* NOTDEF */
  2793.           }
  2794.  
  2795.         delimiter = 0;
  2796.  
  2797.         if (old_delimiter == '"' && character == '`')
  2798.           {
  2799.             delimiter = old_delimiter;
  2800.             old_delimiter = 0;
  2801.           }
  2802.  
  2803.         goto got_character;
  2804.           }
  2805.       }
  2806.  
  2807.     if (!delimiter || delimiter == '`' || delimiter == '"')
  2808.       {
  2809.         if (character == '$')
  2810.           {
  2811.         peek_char = shell_getc (1);
  2812.         shell_ungetc (peek_char);
  2813.         if (peek_char == '(')
  2814.           {
  2815.             if (!delimiter)
  2816.               dollar_paren_level++;
  2817.             else
  2818.               delimited_paren_level++;
  2819.  
  2820.             pass_next_character++;
  2821.             goto got_character;
  2822.           }
  2823.         else if (peek_char == '[')
  2824.           {
  2825.             if (!delimiter)
  2826.               dollar_bracket_level++;
  2827.  
  2828.             pass_next_character++;
  2829.             goto got_character;
  2830.           }
  2831.           }
  2832.  
  2833.         /* If we are parsing a $() or $[] construct, we need to balance
  2834.            parens and brackets inside the construct.  This whole function
  2835.            could use a rewrite. */
  2836.         if (character == '(')
  2837.           {
  2838.         if (delimiter && delimited_paren_level)
  2839.           delimited_paren_level++;
  2840.  
  2841.         if (!delimiter && dollar_paren_level)
  2842.           dollar_paren_level++;
  2843.           }
  2844.  
  2845.         if (character == '[')
  2846.           {
  2847.         if (!delimiter && dollar_bracket_level)
  2848.           dollar_bracket_level++;
  2849.           }
  2850.  
  2851.         /* This code needs to take into account whether we are inside a
  2852.            case statement pattern list, and whether this paren is supposed
  2853.            to terminate it (hey, it could happen).  It's not as simple
  2854.            as just using in_case_pattern_list, because we're not parsing
  2855.            anything while we're reading a $( ) construct.  Maybe we
  2856.            should move that whole mess into the yacc parser. */
  2857.         if (character == ')')
  2858.           {
  2859.         if (delimiter && delimited_paren_level)
  2860.           delimited_paren_level--;
  2861.  
  2862.         if (!delimiter && dollar_paren_level)
  2863.           {
  2864.             dollar_paren_level--;
  2865.             goto got_character;
  2866.           }
  2867.           }
  2868.  
  2869.         if (character == ']')
  2870.           {
  2871.         if (!delimiter && dollar_bracket_level)
  2872.           {
  2873.             dollar_bracket_level--;
  2874.             goto got_character;
  2875.           }
  2876.           }
  2877.       }
  2878.  
  2879.     if (!dollar_paren_level && !dollar_bracket_level && !delimiter &&
  2880.         member (character, " \t\n;&()|<>"))
  2881.       {
  2882.         shell_ungetc (character);
  2883.         goto got_token;
  2884.       }
  2885.     
  2886.     if (!delimiter)
  2887.       {
  2888.         if (character == '"' || character == '`' || character == '\'')
  2889.           {
  2890.         quoted = 1;
  2891.         delimiter = character;
  2892.         goto got_character;
  2893.           }
  2894.       }
  2895.  
  2896.     if (all_digits) all_digits = digit (character);
  2897.     if (character == '$') dollar_present = 1;
  2898.  
  2899.       got_character:
  2900.  
  2901.     token[token_index++] = character;
  2902.  
  2903.     if (token_index == (token_buffer_size - 1))
  2904.       token = (char *)xrealloc (token, (token_buffer_size
  2905.                         += TOKEN_DEFAULT_GROW_SIZE));
  2906.     {
  2907.       char *decode_prompt_string ();
  2908.  
  2909.     next_character:
  2910.       if (character == '\n' && interactive && yy_input_type != st_string)
  2911.         prompt_again ();
  2912.     }
  2913.     /* We want to remove quoted newlines (that is, a \<newline> pair)
  2914.        unless we are within single quotes or pass_next_character is
  2915.        set (the shell equivalent of literal-next). */
  2916.     character = shell_getc ((delimiter != '\'') && (!pass_next_character));
  2917.       }
  2918.  
  2919.   got_token:
  2920.  
  2921.     token[token_index] = '\0';
  2922.     
  2923.     if ((delimiter || dollar_paren_level || dollar_bracket_level) && character == EOF)
  2924.       {
  2925.     if (dollar_paren_level && !delimiter)
  2926.       delimiter = ')';
  2927.     else if (dollar_bracket_level && !delimiter)
  2928.       delimiter = ']';
  2929.  
  2930.     report_error ("Unexpected EOF.    Looking for `%c'.", delimiter);
  2931.     return (-1);
  2932.       }
  2933.  
  2934.     if (all_digits)
  2935.       {
  2936.     /* Check to see what thing we should return.  If the last_read_token
  2937.        is a `<', or a `&', or the character which ended this token is
  2938.        a '>' or '<', then, and ONLY then, is this input token a NUMBER.
  2939.        Otherwise, it is just a word, and should be returned as such. */
  2940.  
  2941.     if ((character == '<' || character == '>') ||
  2942.         (last_read_token == LESS_AND ||
  2943.          last_read_token == GREATER_AND))
  2944.       {
  2945.         yylval.number = atoi (token); /* was sscanf (token, "%d", &(yylval.number)); */
  2946.         return (NUMBER);
  2947.       }
  2948.       }
  2949.  
  2950.     /* Handle special case.  IN is recognized if the last token
  2951.        was WORD and the token before that was FOR or CASE. */
  2952.     if ((last_read_token == WORD) &&
  2953.     ((token_before_that == FOR) || (token_before_that == CASE)) &&
  2954.     (STREQ (token, "in")))
  2955.       {
  2956.     if (token_before_that == CASE)
  2957.       {
  2958.         in_case_pattern_list = 1;
  2959.         allow_esac_as_next++;
  2960.       }
  2961.     return (IN);
  2962.       }
  2963.  
  2964.     /* Ditto for DO in the FOR case. */
  2965.     if ((last_read_token == WORD) && (token_before_that == FOR) &&
  2966.     (STREQ (token, "do")))
  2967.       return (DO);
  2968.  
  2969.     /* Ditto for ESAC in the CASE case. 
  2970.        Specifically, this handles "case word in esac", which is a legal
  2971.        construct, certainly because someone will pass an empty arg to the
  2972.        case construct, and we don't want it to barf.  Of course, we should
  2973.        insist that the case construct has at least one pattern in it, but
  2974.        the designers disagree. */
  2975.     if (allow_esac_as_next)
  2976.       {
  2977.     allow_esac_as_next--;
  2978.     if (STREQ (token, "esac"))
  2979.       {
  2980.         in_case_pattern_list = 0;
  2981.         return (ESAC);
  2982.       }
  2983.       }
  2984.  
  2985.     /* Ditto for `{' in the FUNCTION case. */
  2986.     if (allow_open_brace)
  2987.       {
  2988.     allow_open_brace = 0;
  2989.     if (STREQ (token, "{"))
  2990.       {
  2991.         open_brace_awaiting_satisfaction++;
  2992.         return ('{');
  2993.       }
  2994.       }
  2995.  
  2996. #ifdef ALIAS
  2997.     /* OK, we have a token.  Let's try to alias expand it, if (and only if)
  2998.        it's eligible. 
  2999.  
  3000.        Criteria:
  3001.         No dollar sign
  3002.         Unquoted
  3003.         Not all digits
  3004.         An identifier (all alphanumeric or underscore, first character
  3005.         is not a digit)
  3006.         Last token read was a command separator or expand_next_alias
  3007.         is set
  3008.         We are currently processing an alias (pushed_string_list is
  3009.         non-empty) and this token is not the same as the alias we're
  3010.         currently processing (or any alias we have previously
  3011.         processed.
  3012.  
  3013.        Special cases that disqualify:
  3014.         In a pattern list in a case statement (in_case_pattern_list)
  3015.     */
  3016.     if (interactive_shell && !dollar_present && !quoted &&
  3017.     !all_digits && !in_case_pattern_list &&
  3018.     (command_token_position (last_read_token) || expand_next_token))
  3019.       {
  3020.     char *alias_expand_word (), *expanded;
  3021.     if (current_token_being_expanded &&
  3022.          ((STREQ (token, current_token_being_expanded)) ||
  3023.           (token_has_been_expanded (token))))
  3024.       goto no_expansion;
  3025.  
  3026.     expanded = alias_expand_word (token);
  3027.     if (expanded)
  3028.       {
  3029.         int len = strlen (expanded), expand_next;
  3030.         char *temp;
  3031.  
  3032.         token_index = 0;    /* effectively erase current token */
  3033.  
  3034.         expand_next = (expanded[len - 1] == ' ') ||
  3035.               (expanded[len - 1] == '\t');
  3036.  
  3037.         temp = savestring (token);
  3038.         push_string (expanded, expand_next, temp);
  3039.         goto re_read_token;
  3040.       }
  3041.     else
  3042.       /* This is an eligible token that does not have an expansion. */
  3043. no_expansion:
  3044.       expand_next_token = 0;
  3045.       }
  3046.     else
  3047.       {
  3048.     expand_next_token = 0;
  3049.       }
  3050. #endif /* ALIAS */
  3051.  
  3052.     /* Check to see if it is a reserved word.  */
  3053.     if (!dollar_present && !quoted &&
  3054.     reserved_word_acceptable (last_read_token))
  3055.       {
  3056.     int i;
  3057.     for (i = 0; token_word_alist[i].word != (char *)NULL; i++)
  3058.       if (STREQ (token, token_word_alist[i].word))
  3059.         {
  3060.           if (token_word_alist[i].token == '{')
  3061.         open_brace_awaiting_satisfaction++;
  3062.  
  3063.           if (in_case_pattern_list && (token_word_alist[i].token != ESAC))
  3064.         break;
  3065.  
  3066.           if (token_word_alist[i].token == ESAC)
  3067.         in_case_pattern_list = 0;
  3068.  
  3069.           return (token_word_alist[i].token);
  3070.         }
  3071.       }
  3072.  
  3073.     /* What if we are attempting to satisfy an open-brace grouper? */
  3074.     if (open_brace_awaiting_satisfaction && strcmp (token, "}") == 0)
  3075.       {
  3076.     open_brace_awaiting_satisfaction--;
  3077.     return ('}');
  3078.       }
  3079.  
  3080.     the_word = (WORD_DESC *)xmalloc (sizeof (WORD_DESC));
  3081.     the_word->word = (char *)xmalloc (1 + strlen (token));
  3082.     strcpy (the_word->word, token);
  3083.     the_word->dollar_present = dollar_present;
  3084.     the_word->quoted = quoted;
  3085.     the_word->assignment = assignment (token);
  3086.  
  3087.     yylval.word = the_word;
  3088.     result = WORD;
  3089.     if (last_read_token == FUNCTION)
  3090.       allow_open_brace = 1;
  3091.   }
  3092.   return (result);
  3093. }
  3094.  
  3095. #if defined (NOTDEF)        /* Obsoleted function no longer used. */
  3096. /* Return 1 if this token is a legal shell `identifier'; that is, it consists
  3097.    solely of letters, digits, and underscores, and does not begin with a 
  3098.    digit. */
  3099. legal_identifier (name)
  3100.      char *name;
  3101. {
  3102.   register char *s;
  3103.  
  3104.   if (!name || !*name)
  3105.     return (0);
  3106.  
  3107.   if (digit (*name))
  3108.     return (0);
  3109.  
  3110.   for (s = name; s && *s; s++)
  3111.     {
  3112.       if (!isletter (*s) && !digit (*s) && (*s != '_'))
  3113.     return (0);
  3114.     }
  3115.   return (1);
  3116. }
  3117. #endif /* NOTDEF */
  3118.  
  3119. #ifdef ALIAS
  3120. /* Return 1 if TOKEN is a command separating token. */
  3121. command_token_position (token)
  3122.      int token;
  3123. {
  3124.   if (member (token, "\n;(|&{") ||
  3125.       token == AND_AND ||
  3126.       token == OR_OR ||
  3127.       token == BANG ||        /* XXX */
  3128.       token == 0)
  3129.     return (1);
  3130.   else
  3131.     return (0);
  3132. }
  3133. #endif /* ALIAS */
  3134.  
  3135. /* Return 1 if TOKEN is a token that after being read would allow
  3136.    a reserved word to be seen, else 0. */
  3137. reserved_word_acceptable (token)
  3138.      int token;
  3139. {
  3140.   if (member (token, "\n;()|&{") ||
  3141.       token == AND_AND ||
  3142.       token == OR_OR ||
  3143.       token == SEMI_SEMI ||
  3144.       token == DO ||
  3145.       token == IF ||
  3146.       token == WHILE ||
  3147.       token == UNTIL ||
  3148.       token == THEN ||
  3149.       token == ELSE ||
  3150.       token == ELIF ||
  3151.       token == BANG ||
  3152.       token == 0)
  3153.     return (1);
  3154.   else
  3155.     return (0);
  3156. }
  3157.  
  3158. #if defined (READLINE)
  3159. /* Called after each time readline is called.  This insures that whatever
  3160.    the new prompt string is gets propagated to readline's local prompt
  3161.    variable. */
  3162. reset_readline_prompt ()
  3163. {
  3164.   if (prompt_string_pointer && *prompt_string_pointer)
  3165.     {
  3166.       char *temp_prompt, *decode_prompt_string ();
  3167.  
  3168.       temp_prompt = decode_prompt_string (*prompt_string_pointer);
  3169.  
  3170.       if (!temp_prompt)
  3171.     temp_prompt = savestring ("");
  3172.  
  3173.       if (current_readline_prompt)
  3174.     free (current_readline_prompt);
  3175.  
  3176.       current_readline_prompt = temp_prompt;
  3177.     }
  3178. }
  3179. #endif
  3180.  
  3181. /* Issue a prompt, or prepare to issue a prompt when the next character
  3182.    is read. */
  3183. prompt_again ()
  3184. {
  3185.   char *temp_prompt, *decode_prompt_string ();
  3186.  
  3187.   ps1_prompt = get_string_value ("PS1");
  3188.   ps2_prompt = get_string_value ("PS2");
  3189.  
  3190.   if (!prompt_string_pointer)
  3191.     prompt_string_pointer = &ps1_prompt;
  3192.  
  3193.   if (*prompt_string_pointer)
  3194.     temp_prompt = decode_prompt_string (*prompt_string_pointer);
  3195.   else
  3196.     temp_prompt = savestring ("");
  3197.  
  3198.   current_prompt_string = *prompt_string_pointer;
  3199.   prompt_string_pointer = &ps2_prompt;
  3200.  
  3201. #if defined (READLINE)
  3202.   if (!no_line_editing)
  3203.     {
  3204.       if (current_readline_prompt)
  3205.     free (current_readline_prompt);
  3206.       
  3207.       current_readline_prompt = temp_prompt;
  3208.     }
  3209.   else
  3210. #endif    /* READLINE */
  3211.     {
  3212.       if (interactive)
  3213.     {
  3214.       fprintf (stderr, "%s", temp_prompt);
  3215.       fflush (stderr);
  3216.     }
  3217.       free (temp_prompt);
  3218.     }
  3219. }
  3220.  
  3221. /* This sucks. but it is just a crock for System V systems.  The whole idea
  3222.    of MAXPATHLEN is a crock if you ask me.  Why can't we just have
  3223.    dynamically defined sizes?  (UCSB crashes every 20 minutes on me.) */
  3224. #ifndef MAXPATHLEN
  3225. #if !defined(atarist)
  3226. #define MAXPATHLEN 1024
  3227. #else 
  3228. #define MAXPATHLEN 128
  3229. #endif
  3230. #endif    /* MAXPATHLEN */
  3231.  
  3232. /* Return a string which will be printed as a prompt.  The string
  3233.    may contain special characters which are decoded as follows:
  3234.    
  3235.     \t    the time
  3236.     \d    the date
  3237.     \n    CRLF
  3238.     \s    the name of the shell
  3239.     \w    the current working directory
  3240.     \W    the last element of PWD
  3241.     \u    your username
  3242.     \h    the hostname
  3243.     \#    the command number of this command
  3244.     \!    the history number of this command
  3245.     \$    a $ or a # if you are root
  3246.     \<octal> character code in octal
  3247.     \\    a backslash
  3248. */
  3249. #include <sys/param.h>
  3250. #include <time.h>
  3251.  
  3252. #define PROMPT_GROWTH 50
  3253. char *
  3254. decode_prompt_string (string)
  3255.      char *string;
  3256. {
  3257.   int result_size = PROMPT_GROWTH;
  3258.   int result_index = 0;
  3259.   char *result = (char *)xmalloc (PROMPT_GROWTH);
  3260.   int c;
  3261.   char *temp = (char *)NULL;
  3262.  
  3263.   result[0] = 0;
  3264.   while (c = *string++)
  3265.     {
  3266.       if (c == '\\')
  3267.     {
  3268.       c = *string;
  3269.  
  3270.       switch (c)
  3271.         {
  3272.  
  3273.         case '0':
  3274.         case '1':
  3275.         case '2':
  3276.         case '3':
  3277.         case '4':
  3278.         case '5':
  3279.         case '6':
  3280.         case '7':
  3281.           {
  3282.         char octal_string[4];
  3283.         int n;
  3284.  
  3285.         strncpy (octal_string, string, 3);
  3286.         octal_string[3] = '\0';
  3287.  
  3288.         n = read_octal (octal_string);
  3289.  
  3290.         temp = savestring ("\\");
  3291.         if (n != -1)
  3292.           {
  3293.             string += 3;
  3294.             temp[0] = n;
  3295.           }
  3296.  
  3297.         c = 0;
  3298.         goto add_string;
  3299.           }
  3300.       
  3301.         case 't':
  3302.         case 'd':
  3303.  
  3304.           /* Make the current time/date into a string. */
  3305.           {
  3306.         long the_time = time (0);
  3307.         char *ttemp = ctime (&the_time);
  3308.         temp = savestring (ttemp);
  3309.  
  3310.         if (c == 't')
  3311.           {
  3312.             strcpy (temp, temp + 11);
  3313.             temp[8] = '\0';
  3314.           }
  3315.         else
  3316.           temp[10] = '\0';
  3317.  
  3318.         goto add_string;
  3319.           }
  3320.  
  3321.         case 'n':
  3322.           temp = savestring ("\r\n");
  3323.           goto add_string;
  3324.  
  3325.         case 's':
  3326.           {
  3327.         extern char *shell_name;
  3328.         temp = savestring (shell_name);
  3329.         goto add_string;
  3330.           }
  3331.     
  3332.         case 'w':
  3333.         case 'W':
  3334.           {
  3335.         /* Use the value of PWD because it is much more effecient. */
  3336. #define EFFICIENT
  3337. #ifdef EFFICIENT
  3338.         char *polite_directory_format (), t_string[MAXPATHLEN];
  3339.  
  3340.         temp = get_string_value ("PWD");
  3341.  
  3342.         if (!temp)
  3343.           getwd (t_string);
  3344.         else
  3345.           strcpy (t_string, temp);
  3346. #else
  3347.         getwd (t_string);
  3348. #endif    /* EFFICIENT */
  3349.  
  3350.         if (c == 'W')
  3351.           {
  3352.             char *dir = (char *)rindex (t_string, '/');
  3353.             if (dir && dir != t_string)
  3354.               strcpy (t_string, dir + 1);
  3355.             temp = savestring (t_string);
  3356.           }
  3357.         else
  3358.           temp = savestring (polite_directory_format (t_string));
  3359.         goto add_string;
  3360.           }
  3361.       
  3362.         case 'u':
  3363.           {
  3364.         extern char *current_user_name;
  3365.         temp = savestring (current_user_name);
  3366.  
  3367.         goto add_string;
  3368.           }
  3369.  
  3370.         case 'h':
  3371.           {
  3372.         extern char *current_host_name;
  3373.         char *t_string;
  3374.  
  3375.         temp = savestring (current_host_name);
  3376.         if (t_string = (char *)index (temp, '.'))
  3377.           *t_string = '\0';
  3378.         
  3379.         goto add_string;
  3380.           }
  3381.  
  3382.         case '#':
  3383.           {
  3384.         extern int current_command_number;
  3385.         char number_buffer[20];
  3386.         sprintf (number_buffer, "%d", current_command_number);
  3387.         temp = savestring (number_buffer);
  3388.         goto add_string;
  3389.           }
  3390.  
  3391.         case '!':
  3392.           {
  3393.         extern int history_base, where_history ();
  3394.         char number_buffer[20];
  3395.  
  3396.         using_history ();
  3397.         if (get_string_value ("HISTSIZE"))
  3398.           sprintf (number_buffer, "%d",
  3399.                history_base + where_history ());
  3400.         else
  3401.           strcpy (number_buffer, "!");
  3402.         temp = savestring (number_buffer);
  3403.         goto add_string;
  3404.           }
  3405.  
  3406.         case '$':
  3407.           temp = savestring (geteuid () == 0 ? "#" : "$");
  3408.           goto add_string;
  3409.  
  3410.         case '\\':
  3411.           temp = savestring ("\\");
  3412.           goto add_string;
  3413.  
  3414.         default:
  3415.           temp = savestring ("\\ ");
  3416.           temp[1] = c;
  3417.  
  3418.         add_string:
  3419.           if (c)
  3420.         string++;
  3421.           result =
  3422.         (char *)sub_append_string (temp, result,
  3423.                        &result_index, &result_size);
  3424.           temp = (char *)NULL; /* Free ()'ed in sub_append_string (). */
  3425.           result[result_index] = '\0';
  3426.           break;
  3427.         }
  3428.     }
  3429.       else
  3430.     {
  3431.       while (3 + result_index > result_size)
  3432.         result = (char *)xrealloc (result, result_size += PROMPT_GROWTH);
  3433.  
  3434.       result[result_index++] = c;
  3435.       result[result_index] = '\0';
  3436.     }
  3437.     }
  3438.  
  3439.   /* I don't really think that this is a good idea.  Do you? */
  3440.   if (!find_variable ("NO_PROMPT_VARS"))
  3441.     {
  3442.       WORD_LIST *expand_string (), *list;
  3443.       char *string_list ();
  3444.  
  3445.       list = expand_string (result, 1);
  3446.       free (result);
  3447.       result = string_list (list);
  3448.       dispose_words (list);
  3449.     }
  3450.  
  3451.   return (result);
  3452. }
  3453.  
  3454. /* Report a syntax error, and restart the parser.  Call here for fatal
  3455.    errors. */
  3456. yyerror ()
  3457. {
  3458.   report_syntax_error ((char *)NULL);
  3459.   reset_parser ();
  3460. }
  3461.  
  3462. /* Report a syntax error with line numbers, etc.
  3463.    Call here for recoverable errors.  If you have a message to print,
  3464.    then place it in MESSAGE, otherwise pass NULL and this will figure
  3465.    out an appropriate message for you. */
  3466. report_syntax_error (message)
  3467.      char *message;
  3468. {
  3469.   if (message)
  3470.     {
  3471.       if (!interactive)
  3472.     {
  3473.       char *name = stream_name ? stream_name : "stdin";
  3474.       report_error ("%s:%d: `%s'", name, line_number, message);
  3475.     }
  3476.       else
  3477.     report_error ("%s", message);
  3478.  
  3479.       return;
  3480.     }
  3481.  
  3482.   if (shell_input_line && *shell_input_line)
  3483.     {
  3484.       char *error_token, *t = shell_input_line;
  3485.       register int i = shell_input_line_index;
  3486.       int token_end = 0;
  3487.  
  3488.       if (!t[i] && i)
  3489.     i--;
  3490.  
  3491.       while (i && (t[i] == ' ' || t[i] == '\t' || t[i] == '\n'))
  3492.     i--;
  3493.  
  3494.       if (i)
  3495.     token_end = i + 1;
  3496.  
  3497.       while (i && !member (t[i], " \n\t;|&"))
  3498.     i--;
  3499.  
  3500.       while (i != token_end && member (t[i], " \n\t"))
  3501.     i++;
  3502.  
  3503.       if (token_end)
  3504.     {
  3505.       error_token = (char *)alloca (1 + (token_end - i));
  3506.       strncpy (error_token, t + i, token_end - i);
  3507.       error_token[token_end - i] = '\0';
  3508.  
  3509.       report_error ("syntax error near `%s'", error_token);
  3510.     }
  3511.       else if ((i == 0) && (token_end == 0))    /* a 1-character token */
  3512.     {
  3513.       error_token = (char *) alloca (2);
  3514.       strncpy(error_token, t + i, 1);
  3515.       error_token[1] = '\0';
  3516.  
  3517.       report_error ("syntax error near `%s'", error_token);
  3518.     }
  3519.  
  3520.       if (!interactive)
  3521.     {
  3522.       char *temp = savestring (shell_input_line);
  3523.       char *name = stream_name ? stream_name : "stdin";
  3524.       int l = strlen (temp);
  3525.  
  3526.       while (l && temp[l - 1] == '\n')
  3527.         temp[--l] = '\0';
  3528.  
  3529.       report_error ("%s:%d: `%s'", name, line_number, temp);
  3530.       free (temp);
  3531.     }
  3532.     }
  3533.   else
  3534.     report_error ("Syntax error");
  3535. }
  3536.  
  3537. /* ??? Needed function. ??? We have to be able to discard the constructs
  3538.    created during parsing.  In the case of error, we want to return
  3539.    allocated objects to the memory pool.  In the case of no error, we want
  3540.    to throw away the information about where the allocated objects live.
  3541.    (dispose_command () will actually free the command. */
  3542. discard_parser_constructs (error_p)
  3543.      int error_p;
  3544. {
  3545. /*   if (error_p) {
  3546.      fprintf (stderr, "*");
  3547.   } */
  3548. }
  3549.    
  3550. /* Do that silly `type "bye" to exit' stuff.  You know, "ignoreeof". */
  3551.  
  3552. /* The number of times that we have encountered an EOF character without
  3553.    another character intervening.  When this gets above the limit, the
  3554.    shell terminates. */
  3555. int eof_encountered = 0;
  3556.  
  3557. /* The limit for eof_encountered. */
  3558. int eof_encountered_limit = 10;
  3559.  
  3560. /* If we have EOF as the only input unit, this user wants to leave
  3561.    the shell.  If the shell is not interactive, then just leave.
  3562.    Otherwise, if ignoreeof is set, and we haven't done this the
  3563.    required number of times in a row, print a message. */
  3564. handle_eof_input_unit ()
  3565. {
  3566.   extern int login_shell, EOF_Reached;
  3567.  
  3568.   if (interactive)
  3569.     {
  3570.       /* If the user wants to "ignore" eof, then let her do so, kind of. */
  3571.       if (find_variable ("ignoreeof") || find_variable ("IGNOREEOF"))
  3572.     {
  3573.       if (eof_encountered < eof_encountered_limit)
  3574.         {
  3575.           fprintf (stderr, "Use \"%s\" to leave the shell.\n",
  3576.                login_shell ? "logout" : "exit");
  3577.           eof_encountered++;
  3578.           /* Reset the prompt string to be $PS1. */
  3579.           prompt_string_pointer = (char **)NULL;
  3580.           prompt_again ();
  3581.           last_read_token = current_token = '\n';
  3582.           return;
  3583.         } 
  3584.     }
  3585.  
  3586.       /* In this case EOF should exit the shell.  Do it now. */
  3587.       reset_parser ();
  3588.       exit_builtin ((WORD_LIST *)NULL);
  3589.     }
  3590.   else
  3591.     {
  3592.       /* We don't write history files, etc., for non-interactive shells. */
  3593.       EOF_Reached = 1;
  3594.     }
  3595. }
  3596.